After our magento 2 site is live whenever we are doing changes in JS file it doesn't reflect in customer browser as a result some of the pages breaks for those customer who doesn't flush his browser cache. Is there any way that browser will load fresh file from the server if there is any changes in the file.

Thanks in Advance I am facing this issue in magento 2

  • You have tried versioning? mage2.pro/t/topic/3476 Jun 28, 2019 at 12:02
  • We can't add versioning in production site
    – anjanbarik
    Jun 28, 2019 at 12:06
  • You want to refresh only one javascript file when your js changes? Jun 28, 2019 at 12:09
  • Anything will work.
    – anjanbarik
    Jun 28, 2019 at 12:19

2 Answers 2


Rizwan is correct that adding a version number in the path or query string is the way to do it. Magento 2 has a built in method for handling this. From the command line you can run:

php -f bin/magento config:set dev/static/sign 1

Or from Admin you can go to Stores > Settings > Configuration > Advanced > Developer > Static File Settings and set Sign Static Files to True.

After changing the setting, make sure to recreate static files:

php -f bin/magento setup:static-content:deploy -f

I don't know why this wouldn't be on by default!


You can add a query string to your javascript file URL in order to take effect in your customer browsers. like below example.


Change your version when you make changes in your js file.

  • How you can do that in magento 2?
    – anjanbarik
    Jul 1, 2019 at 7:39
  • which js you want to take effect? is it magento default or your custom. Jul 1, 2019 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.