I want to add version in js and css files in Magento2. I want browser to request url like


Instead of


How can I achieve this ? In which file I need to make the changes.

Thank you


You need to enable the config option "Sign Static Files", as per the documentation:

To enable signed static files:

  1. On the Admin sidebar, tap Stores. Then under Settings, choose Configuration.
  2. In the panel on the left under Advanced, choose Developer.
  3. Expand the Static Files Settings section.
  4. Set Sign Static Files to “Yes.”
  5. When complete, tap Save Config.
  • In firefox the css and js files is already stored in local cache. No matter what I do it never fetches the fresh content from server. If I use static sign files the url I get is example.com/pub/ver3423427/static/print.min.js . But when I open browser it always request example.com/pub/static/print.min.js . That's why I want to add version like print.min.js?ver=1.0.0 . – linux404 Dec 4 '17 at 5:24
  • @linux404 I'm not sure what your problem is. Enabling this configuration will include a version tag, as in your example, in the URL (ver3423427). This means the browser will load a new version of that asset. – Danny Nimmo Dec 4 '17 at 6:00
  • It is not working. In Firefox it always fetching from local cache. The js and css url path is not changing. I checked in developer console request url has not added version part. – linux404 Dec 4 '17 at 8:56
  • Make sure you flush your Magento cache after changing the configuration, and run bin/magento setup:static-content:deploy. Also, make sure you have a rewrite in place for the verXXXX URLs, for example in the Magento supplied sample nginx conf. – Danny Nimmo Dec 4 '17 at 21:55
  • Go to menu Content > Design : Configuration

  • Edit default Global scope > Edit

  • Look at the bottom toggle "Other Settings" > HTML Head

  • Add version in the end.

Run command in command prompt

php bin/magento setup:static-content:deploy

and clear cache it will work

  • How about files like print.min.css,styles-l.min.css which are inside pub/static directory ? – linux404 Dec 3 '17 at 14:41
  • check vendor\magento\theme-frontend-blank\Magento_Theme\layout\default_head_blocks.xml you can override this layout and change version – Rama Chandran M Dec 4 '17 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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