7

When I want to force reload CSS and JS on my sites (non-Magento 2), I usually just add a query string to the end of the URLs. For example: css/styles.css?v=1

I tried this in M2 by adding adding the above to my style files in my custom default_head_blocks.xml Although the style files are being loaded (I can click on the links in 'View Source' and it shows me the correct CSS file content) but the page isn't being styled.

Any idea why it's not working? Or, do you know how to force reload CSS / JS on the client side in M2?

asked Apr 28, 2016 at 17:18

1 Answer 1

2

Magento 2 has this ability built-in called "Sign Static Files". It doesn't use the query string, but uses a generated subfolder starting with "version....", but basically the same idea. You can find it here... Stores> Configuration> Advanced> Developer> Static Files Settings> Sign Static Files

Here's more info on Using Static File Signatures.


Side note for anyone here using Magento 1... for Magento 1 I have used the Queryfier extension by Bubble Code and it does a great job (it uses the query string method).

answered Feb 27, 2017 at 18:00
2
  • This option is only available in developer mode. What is the flow for production mode? Commented Sep 17, 2020 at 14:39
  • 1
    These settings are available via command line using config:set since they need to be set prior to the code being built in Production mode. You can run bin/magento config:set dev/static/sign 1 to enable this. More details available at... devdocs.magento.com/guides/v2.4/config-guide/cache/… Commented Sep 18, 2020 at 19:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.