Looking at the image below, you can see that there are lots of javascript and css in my application. ;
Is there a way in ZEND framework that I can cache all of these so that the page will not load all these stylesheets and scripts?
The issue is not really not a Zend Framework issue. It's about directing the client (a web browser, in all likelihood) to cache the content on its side so that the next time it needs it, it doesn't have to request it and the server doesn't have to deliver it.
This is typically accomplished by sending cache headers from the server to the client. The precise headers you need to send depend upon how long you want the browser to cache. A Google search will show you those.
In a "standard" Zend Framework application, these external javascript and css resources are inside the public
folder of your application and are served directly by your web server. Zend Framework never even touches them. As a result, the method for sending those cache headers will not depend upon Zend Framework, but rather your web server.
As an example, in Apache, if you have the mod_expires module, Apache itself can be instructed to send the correct cache headers. Add something like this to the .htaccess
in public/assets
directory:
ExpiresDefault "access plus 1 month"
See the mod_expires documentation for more info.
Of course, when you update any of the content in that public/assets
directory, you will want all clients to request the new content, not re-use the cached content. Changing the url of the requested resource by appending a query string - something like changing from http://example.com/assets/js/myscript.js
to http://example.com/assets/js/myscript.js?v=20120223
- will force a new load.