The issue at hand is not specifically related to Zend Framework but rather involves instructing the client, likely a web browser, to cache content on its end. This way, when the content is needed again, it can be retrieved without requesting it from the server.
To achieve this, one must send cache headers from the server to the client. The specific headers required depend on how long you wish for the browser to cache the content. A simple Google search can provide guidance on determining these headers.
In a typical Zend Framework application, external JavaScript and CSS resources are located within the public
directory of the application and are directly served by the web server without Zend Framework's involvement. Therefore, the method for sending cache headers will be determined by your web server rather than Zend Framework.
For instance, in Apache, using the mod_expires module allows Apache itself to send the necessary cache headers. By adding a directive like the following to the .htaccess
file in the public/assets
directory:
ExpiresDefault "access plus 1 month"
Refer to the mod_expires documentation for further information.
Keep in mind that whenever content in the public/assets
directory is updated, it may be necessary to prompt all clients to request the new content instead of using cached content. One approach to achieving this is by altering the URL of the requested resource by appending a query string, such as changing from
http://example.com/assets/js/myscript.js
to
http://example.com/assets/js/myscript.js?v=20120223
, which forces a fresh load.