3

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 3

2

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
2

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>
9
  • Sign Static Files is already set to yes
    – Ghulam.M
    Jul 10, 2019 at 10:37
  • Are you using PWA or any third party cache? Jul 10, 2019 at 10:46
  • are you talking about cache buster??
    – Ghulam.M
    Jul 17, 2019 at 5:14
  • 1
    Since 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
  • is there any solution for pwa or varnish??
    – Ghulam.M
    Jul 17, 2019 at 5:53
2

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:

magestore-blog

requirejs-doc

stackissue

Your Answer

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

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