Jump to content

Leverage browser caching


Recommended Posts

How to do the Leverage browser caching

Based on Google developer site health analysis

1. Leverage browser caching

Details -

Leverage browser caching
Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.
Leverage browser caching for the following cacheable resources:
----
----
---
Link to comment
Share on other sites

Key word in there, 'static'. IP.Board, by it's nature, is 'dynamic'. Content is ever changing based on permissions, content added, etc.

If you're using apache, you can use mod_expires, but be warned, it can cause issues if used improperly on dynamic pages.

Link to comment
Share on other sites

  • 3 weeks later...

Never cache dynamic PHP pages. What this is saying is you need to set caching headers for your static elements. Basically forum style elements, avatars and the sort.

Add some caching rules for content in /public and /uploads and you should be good. Caching these elements for one week+ is usually a good idea. Any time avatars/templates are updated, the nocache query string should update and cause the browser to re-download the new version regardless of how long you cache elements for.

These are the old Apache rules I used for this,

<Directory /path/to/www/public/>
        <filesMatch ".(jpg|jpeg|png|gif|swf|ico|css|js|pdf|flv)$">
                Header set Cache-Control "max-age=604800, public"
        </filesMatch>
</Directory>
<Directory /path/to/www/uploads/>
        <filesMatch ".(jpg|jpeg|png|gif|swf|ico|css|js|pdf|flv)$">
                Header set Cache-Control "max-age=604800, public"
        </filesMatch>
</Directory>
Link to comment
Share on other sites

  • 5 months later...

Never cache dynamic PHP pages. What this is saying is you need to set caching headers for your static elements. Basically forum style elements, avatars and the sort.

Add some caching rules for content in /public and /uploads and you should be good. Caching these elements for one week+ is usually a good idea. Any time avatars/templates are updated, the nocache query string should update and cause the browser to re-download the new version regardless of how long you cache elements for.

These are the old Apache rules I used for this,

<Directory /path/to/www/public/>
        <filesMatch ".(jpg|jpeg|png|gif|swf|ico|css|js|pdf|flv)$">
                Header set Cache-Control "max-age=604800, public"
        </filesMatch>
</Directory>
<Directory /path/to/www/uploads/>
        <filesMatch ".(jpg|jpeg|png|gif|swf|ico|css|js|pdf|flv)$">
                Header set Cache-Control "max-age=604800, public"
        </filesMatch>
</Directory>

I have a question, please:

Where to put this? inside the .htaccess ?

Link to comment
Share on other sites

We do actually cache our dynamic forum pages. We do this in certain cases for guests. Members always get the latest version off course.

For more information and tips see: http://community.invisionpower.com/topic/364153-great-results-with-nginx-cache/page-6?hl=nginx#entry2401354

I advise you to read all the tips and first test this in a separate environment with some of your users.You don't want to create nasty results where some members can view pages as other members.

I think the Google developer (Did you use Pagespeed Insight?) is referring to images and other static content as mentioned by the members above me. This can be easily achieved by adding a .htaccess file if you are using Apache or preferable set the expires value for static content in Nginx to it's maximum ( expires max; ).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...