5 de nov. de 2012

Configure mod_expires on apache 2.2

This module 'mod_expires' is used to apply a correct header to your contents. Actually it is very powerful to add max perform to your site. The browser will be access the content only at the exact moment, defined by us.

For Example:

I have a simple application on my application server, to access her, i use the url http://localhost/my_application/index.html, in front of application server has installed a apache 2.2 server.

1) With this configuration, all html files sended to client by my_application gets a Cache-Control, Date and Keep-Alived attributes correctly defined. The client do not access my_application when this attributes does not expire.

<LocationMatch "^/my_application/html/.*">
     ExpiresActive On
     ExpiresByType text/html                     "access plus 3 seconds"
     ExpiresDefault "access plus 1 month 15 days 2 hours"
 </LocationMatch>


2) Open the address http://localhost/my_application/index.html with your Mozilla Firefox with Firebug component and click on "network", "all" and "header of response", you see:

Cache-Control    max-age=3
Connection    Keep-Alive
Content-Length    0
Content-Type    text/html
Date    Mon, 15 Sep 2012 20:38:49 GMT
Expires    Mon, 15 Sep 2012 20:39:08 GMT

3) Open another address when this match (text/html) is false, for example  http://localhost/my_application/my_custom_javascript.js. See, the document will be read for browser only 1 month and 15 days last:

Cache-Control    max-age=2700
Connection    Keep-Alive
Content-Length    0
Content-Type    application/x-javascript
Date    Mon, 01 Nov 2012 20:38:49 GMT
Expires    Mon, 01 Nov 2012 20:39:08 GMT

4) Another possible examples:

<LocationMatch "^/my_application/(javascript|css|js|styles|etc)/.**">
  ExpiresActive On
  ExpiresByType application/x-javascript     "M6048899"
  ExpiresByType text/css                     "M6048810"
  ExpiresDefault "M60488111"

</LocationMatch>

5) Restart your apache server.

More informations from url: http://httpd.apache.org/docs/2.2/mod/mod_expires.html


Nenhum comentário:

Postar um comentário