Chrome doesn't recognize my changes on my javascript file and loads old code?

One solution for this problem is to force reloading the resource in order to avoid the cache. You can get this modifying the url with http get parameters:

Change:

<script src="myscripts.js"></script>

to:

<script src="myscripts.js?newversion"></script>

Where newversion can be any string as it will be ignored. A useful option is to use the date, or version, of your code.

I found this workaround particularly useful when I came across this same problem and wanted to ensure that all clients (not just my own browser!) would run the new version of the code.


I think there's an even better way:

You can use PHP to add the last modification date of your JavaScript file to the URI of that file.

<script src="js/my-script.js?<?php echo filemtime('js/my-script.js'); ?>"> 
</script>

The browser will receive:

<script src="js/my-script.js?1524155368"></script>

The URI of the file will automatically change if the file is updated.

This way the browser can still cache unchanged files while recognizing changes instantly.