Leverage browser caching for jpg

14 views
Skip to first unread message

Plastica

unread,
Feb 14, 2010, 6:24:44 PM2/14/10
to page-speed-discuss
I am trying to improve the speed of the download of my site.

When I consulted page speed I scored a 77. On the section for
leverage browser caching "The following resources are missing a cache
expiration..." there is a list of all the images on the page.

I tried to make an .htaccess file with specific expiration dates and
also with the 1 month after access date and uploaded to my image
subdirectory.

<FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
Header set Cache-Control “max-age=2419200, public”
</FilesMatch>

In all cases this resulted in no images appearing on the pages at
all.

I have tried a number of other versions that appear in these
discussions

# 1 YEAR
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|js|css)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>


# Asset Expiration
ExpiresActive On
<FilesMatch "\.(ico|gif|jpe?g|png|js|css)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>

And still the same issue occurs when I put the htaccess in my
subdirectory, any idea what am I doing wrong? Is there another way to
deal with this issue? Thanks for your help.

Bryan McQuade

unread,
Feb 16, 2010, 4:31:43 PM2/16/10
to page-spee...@googlegroups.com
You might need to clear your browser's cache and reload the page
before re-running the page speed analysis.

For most accurate results in cases like these, I suggest clearing the
browser cache, quitting the browser, then restarting the browser with
a fresh empty cache.

> --
> You received this message because you are subscribed to the Google Groups "page-speed-discuss" group.
> To post to this group, send email to page-spee...@googlegroups.com.
> To unsubscribe from this group, send email to page-speed-disc...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/page-speed-discuss?hl=en.
>
>

Plastica

unread,
Feb 16, 2010, 9:32:11 PM2/16/10
to page-speed-discuss
OK I tried this and incredibly my score is now 73 with leverage
browser still high on the list.

> > For more options, visit this group athttp://groups.google.com/group/page-speed-discuss?hl=en.- Hide quoted text -
>
> - Show quoted text -

Bruno

unread,
Feb 17, 2010, 5:08:50 AM2/17/10
to page-speed-discuss
Page speed consider that the cache must be higher than one month. Your
value is actually 28 days (2419200 seconds).

I also think that the following code is easier to maintain (you can
have a jpg image generated by php)
ExpiresActive On
ExpiresByType image/gif A2678400 # 31 days = OK for
page speed
ExpiresByType image/png A2678400
ExpiresByType image/jpeg A2678400
ExpiresByType text/css A2678400
ExpiresByType application/javascript A2678400
ExpiresByType application/x-javascript A2678400
...
Whatever you want

> > > For more options, visit this group athttp://groups.google.com/group/page-speed-discuss?hl=en.-Hide quoted text -

Plastica

unread,
Feb 17, 2010, 11:42:20 AM2/17/10
to page-speed-discuss
Thank you this was helpful in that it did not remove my images for the
current site. It did not seem to have any impact on my page speed
though which still is asking me to leverage browser cache (even after
removing cache from firefox).

> > > > For more options, visit this group athttp://groups.google.com/group/page-speed-discuss?hl=en.-Hidequoted text -
>
> > > - Show quoted text -- Hide quoted text -

Bruno

unread,
Feb 22, 2010, 4:21:31 AM2/22/10
to page-speed-discuss
Well, I'm looking at my own website, and it appear that google rules
have change and caching is now recommended for one year, as said in
this message : "To further improve cache hit rate, specify an
expiration one year in the future for the following cacheable
resources:"

Actually, It's quite logical, I've seen many website with static files
older than one year...

Then you know what you have to do.

> > > > > For more options, visit this group athttp://groups.google.com/group/page-speed-discuss?hl=en.-Hidequotedtext -

Vitaly Makarkin

unread,
Feb 25, 2010, 12:36:01 PM2/25/10
to page-speed-discuss
Hello,

Please let me know.

Am I need add this into the end of .htaccess file and change A2678400
to A32140800 ?

Thx, Vitaly

> > > > For more options, visit this group athttp://groups.google.com/group/page-speed-discuss?hl=en.-Hidequoted text -

Dariusz Haratyk

unread,
Feb 25, 2010, 2:45:01 PM2/25/10
to page-speed-discuss
First check if you have mod_expires ;)
Then check out http://www.speedingupwebsite.com/2010/01/13/5x-speedup-with-client-side-caching/
they posted massive rule for caching. Probably 90% of files you can
add to your site is there.

Billy Hoffman

unread,
Feb 25, 2010, 3:34:16 PM2/25/10
to page-spee...@googlegroups.com
[Sigh] You cannot just blindly implement far-future caching
directives. Unless you are 100% certain you will never change the
content, you need to have some kind of process in place to do change
control. Want to update logo.gif? Then you'll need to change to the
URL/filename. Do the developers know that? Did you tell them? How are
you going to make sure the URL always changes when the source image
does?

The Apache config you linked to contains other problems too. For
example, it caches .ICO files for 10 years. Want to change your
Favicon? Well now you cannot.

I cannot stress enough that a most performance optimizations are not
something that you can do without a plan or process in place or
without coordinating with all the people involved with the design,
development and operations of a web site. Otherwise you end up with
problems and inconsistency.

Billy Hoffman
--
http://zoompf.com/

Dariusz Haratyk

unread,
Feb 25, 2010, 3:52:18 PM2/25/10
to page-speed-discuss
I didn't say just to ctrl+c, ctrl+v but to see at that post and copy
things that he need.
i.e. he doesn't have <IfModule mod_expires.c> which can cause problems
- i've got such problem - withouth it doesn't worked - with it it
works like a charm.

And yes, i'm aware that if this is big site then you should inform all
the people responsible for it.

Sam Kerner

unread,
Feb 25, 2010, 5:25:08 PM2/25/10
to page-spee...@googlegroups.com
On Thu, Feb 25, 2010 at 3:34 PM, Billy Hoffman <billym...@gmail.com> wrote:
> [Sigh] You cannot just blindly implement far-future caching
> directives. Unless you are 100% certain you will never change the
> content, you need to have some kind of process in place to do change
> control. Want to update logo.gif? Then you'll need to change to the
> URL/filename. Do the developers know that? Did you tell them? How are
> you going to make sure the URL always changes when the source image
> does?

This is an important point. Caching should only be enabled for
content that will not change. In our docs, we recommend
fingerprinting.

From http://code.google.com/speed/page-speed/docs/caching.html :
"""
Use fingerprinting to dynamically enable caching.

For resources that change occasionally, you can have the browser cache
the resource until it changes on the server, at which point the server
tells the browser that a new version is available. You accomplish this
by embedding a fingerprint of the resource in its URL (i.e. the file
path). When the resource changes, so does its fingerprint, and in
turn, so does its URL. As soon as the URL changes, the browser is
forced to re-fetch the resource. Fingerprinting allows you to set
expiry dates long into the future even for resources that change more
frequently than that. Of course, this technique requires that all of
the pages that reference the resource know about the fingerprinted
URL, which may or may not be feasible, depending on how your pages are
coded.
"""

Perhaps the Page Speed caching rule should explicitly warn about this,
instead of just linking to documentation.

Sam

Bruno

unread,
Feb 26, 2010, 3:57:23 AM2/26/10
to page-speed-discuss
Actually, if you want to follow page speed rules, yes, you have to put
a far expiration date like 372 as you write.
This will help you to improve your page speed mark, but there's one
thing important :
Page speed is an automated tool. It's not something able to "think".
When you wanna choose your cache date time, there's many solution. You
have to check how often static component in your page are changing,
where does images take place, with which name, ...

Actually, the best solution is to put a version number for all your
files header-1.0.jpg for example, or something like (in php)
header.jpg?<?php echo filemtime('header.jpg');?>.
Then, you can put a very far future expiration date (5, 10, 20 years)
there's no matter.

The important thing is to understand that page speed is not a teacher
giving you a mark, but a workmate giving you advices.

> > > > > For more options, visit this group athttp://groups.google.com/group/page-speed-discuss?hl=en.-Hidequotedtext -

Billy Hoffman

unread,
Feb 28, 2010, 9:35:28 AM2/28/10
to page-speed-discuss
Bruno,

Inserting a timedate stamp into the URL for an image is a great way to use far future caching when your images change., However you do not want to put this in the query string of the URL. Most caching proxies will not cache something that has a query string. See Steve Souder's post here:


Enjoy,
Billy
--
Reply all
Reply to author
Forward
0 new messages