Zend Javascript and CSS caching

October 25th, 2012 by piter Leave a reply »

How often, when developing/testing a website, did you ask your customer to clear his browser cache?
Ok, your client can clear his cache… But what about a live application? How to tell users to clear their cache?

So, if you’re using headLink and headScript view helpers I think this will help. The main idea is to overload Zend’s headLink and headScript and add a “versioning” parameter at the end of the url.
Everytime you make a change in css/js you just have to update the “version” in application.ini.

Attached you’ll find the two classes that overload Zend’s headLink and headScript view helpers. Add those in “library/Ze”.

In Bootstrap.php, you’ll have to let the “view” know of those scripts, so add this line in “_initView()” method (after you initialize view):

1
$view->addHelperPath('Ze', 'Ze');

Same thing, in Bootstrap.php, you’ll have to add your config to registry (in case that isn’t added by now):

1
Zend_Registry::set('config', $this->getOptions());

In the end, don’t forget “versions” in application.ini file:

1
2
assets.css.version = 1
assets.js.version = 1

Aaaaannd…. voila!

Attached Files:

Share

Leave a Reply