joomla/joomla-cms — pull request #1618 by phproberto (2013-07-30 03:44:18+00:00)
Title: [imp] Feature #31602 add simple versioning to admin template css and js ...

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:

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

```PHP
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:

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

Example to specify the asset version manually:

```PHP
$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:

```PHP
$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:

```PHP
$doc->setMediatag('23424235346456');
```

Anyone can flush assets cache with:

```PHP
$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