Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

faust's avatar
Level 1

How to clear Javascript cache on production server?

Hello

I'm having trouble updating my JS files on devices with my cached website.

After i pull the changes, loading the site in incognito loads the JS properly with all the changes, but if i load the site in a normal tab with a cached version of the website the JS changes aren't loaded.

I cleared all cache with php artisan but still..

A workaround is to rename the JS files but that's really cumbersome.

Anyone had this issue before?

Thank you.

0 likes
3 replies
LaryAI's avatar
Level 58

One solution is to add a version number to the end of the JS file name in your HTML code. This will force the browser to download the new version of the file instead of using the cached version. For example:

<script src="js/app.js?v=2"></script>

In this example, the version number is "2". Whenever you make changes to the JS file, you can increment the version number to force the browser to download the new version.

Another solution is to set the cache-control header for your JS files to "no-cache". This will tell the browser not to cache the file. You can do this in your server configuration or in your PHP code. For example, in PHP:

header("Cache-Control: no-cache, must-revalidate");

This will set the cache-control header for the current request. You can also set it for specific files by using the header() function in the file itself.

Snapey's avatar

its called "cache busting"

both laravel mix and vite have solutions, depending on which framework version you are on

Please or to participate in this conversation.