0

Looking at the image below, you can see that there are lots of javascript and css in my application. javascripts and css in my app ;

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?

1
  • What do you mean by "cache," and what do you mean by "a way in ZEND?" You can have your web server instruct clients to cache the files. ZEND is a company; it's unclear which of their products you are talking about. Commented Feb 23, 2012 at 1:37

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.