recently we have changed few files js/CSS/phtml
files on our site as we tested them we experienced strange thing in incognito mode the new CSS
and js
is working fine but if we switched to normal mode it loads the old files. The issue was a browser cache as we cleared browser cache everything worked as well. But the problem is that we can't tell our every client to clear their browser cache. Is there any Solution!?
3 Answers
Enable cache busting on static file URLs. This ensures users get the latest version of the assets anytime they update:
php -f bin/magento config:set dev/static/sign 1
To overcome these issues Magento features Static Content Signing which allows you to invalidate Browser Cache. You can enable static content signing by navigating to Stores > Settings > Configuration > Advanced > Developer > Static Files Settings
, Set Sign Static Files
to Yes. Once done each time when you run the deploy command
php bin/magento setup:static-content:deploy
Magento changes the version number so automatically your static files in browser cache are invalidated due to version number change.
http://website.com/pub/static/version1475604434/frontend/Magento/luma/en_US/images/image.png
You can also enable/disable static content signing through this command
php bin/magento config:set dev/static/sign <1 or 0>
-
-
-
-
1Since you are saying have enabled static content signing and still the browser cache doesn't get cleared upon deploying files after css/js change, if you have installed any third party cache servers like varnish etc. or making use of technologies like PWA it might cause troubles for changes to be reflected on end user device Jul 17, 2019 at 5:30
-
This method helped me I have added urlArgs: "bust=" + (new Date()).getTime()
in my requirejs-config.js file now the cache issue is solved for now.
var config = {
map: {
'*': {
bssAjaxCart: 'Vendor_Module/js/ajax'
}
},
urlArgs: "bust=" + (new Date()).getTime()// Disable require js cache
};
REFERENCES: