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?
1 Answer 1
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).
-
This option is only available in developer mode. What is the flow for production mode?Jonas de Herdt– Jonas de Herdt2020年09月17日 14:39:30 +00:00Commented Sep 17, 2020 at 14:39
-
1These settings are available via command line using
config:setsince they need to be set prior to the code being built in Production mode. You can runbin/magento config:set dev/static/sign 1to enable this. More details available at... devdocs.magento.com/guides/v2.4/config-guide/cache/…Scruffy Paws– Scruffy Paws2020年09月18日 19:48:04 +00:00Commented Sep 18, 2020 at 19:48