Success

User tests: Successful: Unsuccessful:

avatar phproberto
phproberto
30 Jul 2013

My proposal to implement @brianteeman suggestion of refresh assets after version updates.

This method creates two new methods to JDocument to allow to load versionable assets:

public function addScriptVersion($url, $version = null, $type = "text/javascript", $defer = false, $async = false)

and:

public function addStyleSheetVersion($url, $version = null, $type = "text/css", $media = null, $attribs = array())

The CMS is able to handle assets versions automatically but third part developers can also specify the assets versions.

Example to allow the system to automatically add version:

$doc->addScriptVersion('templates/' . $this->template . '/js/template.js');

Example to specify the asset version manually:

$doc->addScriptVersion('templates/' . $this->template . '/js/template.js', '1,87');

The automatic version is generated only:

  • When the user session is created
  • On each page load when debug is enabled.

So in the normal mode it would be created only 1 time per user session instead of 1 per page load. The version is built with:

$mediaTag = md5($this->getLongVersion() . $config->get('secret') . $date->toSql());

It uses Joomla! version + secret string in configuration + current date + time.

It also includes one extra check to not add mediatag to assets that already contain it. So in most cases in can directly replace addScript & addStylesheet methods.

This modifies JFactory to add the mediatag on document creation. I saw that JFactory is already using JVersion so it doesn't add additional dependencies. But with this same method we can do it outside JFactory (for example inside a template) with:

$doc->setMediatag('23424235346456');

Anyone can flush assets cache with:

$app = JFactory::getApplication()->flushAssets();

This pull request already includes the code to refresh assets in:

  1. In finaliseUpgrade() method triggered after upgrading joomla.
  2. In the extension installer after install(), discover_install() & uninstall() methods.

Feature tracker issue:
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=31602

Google group discussion (please send your comments there to avoid duplicated discussions):
https://groups.google.com/forum/#!topic/joomla-dev-cms/81ZQ94MCV9A

avatar phproberto phproberto - open - 30 Jul 2013
avatar phproberto
phproberto - comment - 2 Aug 2013

I have updated the pull request with:

  • Flush assets + purge updates after clicking in fix database
  • Fix code to use Joomla! coding standards
  • Fix bug reported by @mbabker
  • Rename "mediatag" to "mediaversion" that describes better the parameter
  • Create generateMediaVersion() and refreshMediaVersion() to ease tests and use of media version by third part extension developers.
  • Create standard reusable helper JLibraryHelper

Tests

Update Joomla!

1-before-update
2-after-update

Install extension

3-before-install-extension
4-after-install-extension

Uninstall extension

5-before-uninstall-extension
6-after-uninstall-extension

Fix database

7-before-fix-database
8-after-fix-database

avatar phproberto
phproberto - comment - 7 Sep 2013

I've merged and rebased it vs the latest master branch to ensure it's still mergeable with Travis approval.

avatar elinw
elinw - comment - 1 Oct 2013

@phproberto Could you update this?

avatar phproberto
phproberto - comment - 3 Oct 2013

This now:

  • Is rebased vs the latest branch
  • Uses the new JApplicationCms
  • Uses libraries/cms to store the library helper to be consistent with #2043

Add a Comment

Login with GitHub to post a comment