1

I faced a problem in Joomla 3. For example, I try to add a JavaScript file with auto-version option:

JHtml::_('script', '/path/to/script.js', array('version' => 'auto'));

It works. CMS adds to HTML something like this:

<script src="/path/to/script.js?1e1d67808f340bae20c17f7434590e08" type="text/javascript"></script>

But when I modify this file, this version remains the same.

I found in core classes Document and Version and methods for manipulations with MediaVersion, but it clarified nothing.

So, my question. How does it works. How this version refreshes?

0

A bit late to the party, but i was wondering the same thing. If you don't set the version yourself in the options off addScript, Joomla will check in the joomla library extension database table row. If the parameter if not set, or if you are in debug mode, it will generate a new version. So, to get a new version, just switch joomla debug on then off.

0

Also late to the party, but the reason for adding the media version to Javascript files etc can be found at https://api.joomla.org/cms-3/classes/Joomla.CMS.Version.html#method_getMediaVersion, by clicking on the getMediaVersion text on that page. To quote:

This media version is used to append to Joomla core media in order to trick browsers into reloading the CSS and JavaScript, because they think the files are renewed. The media version is renewed after Joomla core update, install, discover_install and uninstallation.

The basic reason is that browsers cache CSS and JS files, so you could have the following situation:

  • a user accesses a Joomla site, and the CSS and JS files are downloaded to the user's browser
  • the Joomla instance is upgraded, which involves changing the content of several CSS and JS files, but the filenames remain the same
  • the user accesses the newly-updated site, but the new CSS and JS files aren't reloaded because the user's browser uses the cached versions instead.

If the media version is used, then the src attribute of the <script> tag will be different after the upgrade, and the browser will load the new file.

So if you're developing an extension yourself it's worthwhile using this mechanism with your own CSS and JS files, by using the array('version' => 'auto') option described in the question. This is because Joomla updates the media version when anything is installed or reinstalled on the instance, not just Joomla core.

As mentioned in the other answer, the media version is stored in the extensions table, in the params field of the record with name LIB_JOOMLA. And a new media version is created upon every HTTP request if JDEBUG is enabled.

Looking at the code, the media version is generated from factors including the Joomla version, the Joomla instance secret and the current date/time when the media version is generated.

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.