Enable browser caching of static assets
|
09-13-2010, 02:11 AM
(This post was last modified: 09-13-2010 02:38 AM by yzerfontein.)
Post: #1
|
|||
|
|||
Enable browser caching of static assets
Newbie here. I ran test results on this page:
http://www.southafrica.to/transport/Airl...ights.php5 http://www.webpagetest.org/result/100912...imization/ One of the things which came up is that "Enable browser caching of static assets" FAILED (No max-age or expires). How do I go about fixing this up? I host on Godaddy (note sure if that's relevant). Would appreciate any assistance. |
|||
09-13-2010, 02:28 AM
(This post was last modified: 09-13-2010 02:30 AM by jabubo.)
Post: #2
|
|||
|
|||
RE: Enable browser caching of static assets
Try to add something like this, to an .htaccess file in the root-Folder of your website.
The settings add the expire header for the mime-types (Javascript, CSS, png, jpg and so on) beginning at the time the client access the file and adding the time specified as expiration time. In the code below A604800, stands for accesstime + 604800 seconds is the expiration time. In this time the client do not request the content again. Unless the client uses a local cache. Code: <IfModule mod_expires.c> Just check the HTTP-Header of any file mathing this. If the expire-header is not used, your provider has not enabled mod_expires for the Apache webserver. Ask him to do that. test and execute PHP functions online free and easy => http://www.functions-online.com/home.html |
|||
09-13-2010, 02:58 AM
Post: #3
|
|||
|
|||
RE: Enable browser caching of static assets
Thanks. I added that exact code at http://www.southafrica.to/.htaccess (just copied & pasted).
But I'm still getting the same error at http://www.webpagetest.org/result/100912...imization/ |
|||
09-13-2010, 12:30 PM
Post: #4
|
|||
|
|||
RE: Enable browser caching of static assets
I'd be surprised if they didn't, but check with GoDaddy and make sure they have mod_expires installed and activated for your Apache instance.
Be careful before you turn it on so that you understand the ramifications though. Your site needs to be designed to expect the user to be able to cache those files and never check for an updated version. That means if you update the css and don't change the file name the users with the cached copy will not see the updates (potentially viewing a broken page). |
|||
09-27-2011, 09:37 PM
Post: #5
|
|||
|
|||
RE: Enable browser caching of static assets
(09-13-2010 12:30 PM)pmeenan Wrote: Be careful before you turn it on so that you understand the ramifications though. Your site needs to be designed to expect the user to be able to cache those files and never check for an updated version. That means if you update the css and don't change the file name the users with the cached copy will not see the updates (potentially viewing a broken page).And what are you suggesting to do? i mean how to make users be aware of it? |
|||
09-28-2011, 10:36 AM
Post: #6
|
|||
|
|||
RE: Enable browser caching of static assets
You don't make the users aware of it, it needs to be designed into the site itself. If you are expecting to change css or javascript files then you need to have a system in place where you can change the file name every time you change the contents.
Personally, I do this by having a version number declared in a global file and I bump the version number any time I edit the css or javascript. Anywhere they are included they are included as <file>?v=<version>. The query parameter is just ignored by the web server so the ACTUAL file name can be the same but it's enough to bust the cache. Purists may comment that the query string may prevent intermediate proxies from caching the content and that you should add the version to the URL itself but it wasn't worth the extra effort for my needs. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)