Post by derek » Wed Jun 08, 2011 3:49 pm

I haven't found a solution to this issue. Google PageSpeed suggests caching images & js & css files.

Analysing the demo opencart page also reveals this issue. see:

http://pagespeed.googlelabs.com/#url=ht ... serCaching

Images don't change. So how does one switch on browser caching?

Newbie

Posts

Joined
Thu Aug 12, 2010 3:12 pm

Post by SapporoGuy » Wed Jun 08, 2011 4:19 pm

Strange but the images are saved to a cache directory ...

Would be sweet to implement the html5 browser db/cache ability ...

Anybody know how drupal does this? They have a serious attack attitude towards cacheing drupal sites and it really does show in performance. But with cacheing you do have issues with dynamic and stable content like articles and such which drupal does try to do.

930sc ... because it is fun!


User avatar
Active Member

Posts

Joined
Mon Nov 01, 2010 7:29 pm

Post by derek » Thu Jun 09, 2011 8:29 am

The issue is caching on the users browser not on the opencart server.

I'm finalizing my first opencart site. It has been a slow site even though running on fast hardware. Google PageSpeed identified two important speed issues, 1/ compression (I had that off but now on and noticeably faster), 2/ leverage of browser caching. Here is an example line reported back from Google PageSpeed for the opencart demo page (I get the same error):

http://demo.opencart.com/.../add.png (expiration not specified)

I think the opencart coding is saying do not cache everything. It makes sense not to cache the pages, because they are generated on-the-fly and can change, but images rarely change. It appears that the images are being resent on each page visit even though the potential exists to pull them from the browsers cache.

I also tried this code in the .htaccess file but it made no difference:
#cache control
ExpiresActive On
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
Header set ExpiresDefault "access plus 1 month"
Header set Cache-Control "public, no-transform"
</FilesMatch>


What have I missed?

Newbie

Posts

Joined
Thu Aug 12, 2010 3:12 pm

Post by rph » Thu Jun 09, 2011 8:37 am

I know the following works:

Code: Select all

# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 week
<FilesMatch "\.(gif|jpg|jpeg|png)$">
  ExpiresDefault A604800
  Header append Cache-Control "public"
</FilesMatch>

# Set up 1 week caching on javascript and CSS
<FilesMatch "\.(js|css)$">
  ExpiresDefault A604800
  Header append Cache-Control "proxy-revalidate"
  SetOutputFilter DEFLATE
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch "\.(php)$">
  ExpiresActive Off
  Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
  Header set Pragma "no-cache"
</FilesMatch>

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by derek » Thu Jun 09, 2011 11:26 am

thanks rph,

I put the code into .htaccess but PageSpeed is still not liking it. Try running the test:
http://pagespeed.googlelabs.com/#url=ht ... serCaching


Also, running this tool:
http://web.forret.com/tools/analyze.asp ... als.com.au

returns this header:
* Date = Thu, 09 Jun 2011 03:19:39 GMT
* Server = Apache
* X-Powered-By = PHP/5.2.9
* Expires = Thu, 19 Nov 1981 08:52:00 GMT
* Cache-Control = no-store, no-cache, must-revalidate, post-check=0, pre-check=0,private, no-cache, no-store, proxy-revalidate, no-transform
* Pragma = no-cache,no-cache
* Set-Cookie = PHPSESSID=9884cf566b9ad166568c08dd3e8aebca; path=/,language=en; expires=Sat, 09-Jul-2011 03:19:39 GMT; path=/; domain=www.value-pet-deals.com.au,currency=AUD; expires=Sat, 09-Jul-2011 03:19:39 GMT; path=/; domain=www.value-pet-deals.com.au
* Keep-Alive = timeout=5, max=100
* Connection = Keep-Alive
* Transfer-Encoding = chunked
* Content-Type = text/html; charset=UTF-8



Any clues here?

Newbie

Posts

Joined
Thu Aug 12, 2010 3:12 pm

Post by rph » Thu Jun 09, 2011 4:02 pm

Double check that mod_expires is running on your host maybe? I know the code works because I optimized for Page Speed a long while ago.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by Skyhigh » Thu Jun 09, 2011 5:05 pm

All the .htaccess suggestions in this guide still stand.

How To Speed Up Page Content - Opencart

(although some of the code mods may not, they're done from a 1.3.2 build)

LoveMoissanite.com - Moissanite Rings - Proudly Powered by Opencart
[How To] Speed Up Page Content with Opencart - Opencart advocate since 2009


New member

Posts

Joined
Fri Sep 11, 2009 8:12 pm

Post by derek » Fri Jun 10, 2011 9:14 am

Thanks everyone for those excellent suggestions.

I verified from the host that mod_expires is loaded and running. Also I tried the following - I placed a plain html file on the site outside of the opencart configuration. The header I got back showed no problem (compare this with previous header above):

HTTP/1.1 200 OK
Date: Fri, 10 Jun 2011 00:18:48 GMT
Server: Apache
Last-Modified: Thu, 09 Jun 2011 06:07:57 GMT
Accept-Ranges: bytes
Content-Length: 53
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

I repeated test with an image files from within the opencart site. That cached okay and PageSpeed did not identify the (expiration not specified) problem.

So, what is it about the opencart site that is causing PageSpeed to report (expiration not specified)?
Or, are we seeing a quirk of the google PageSpeed site???

Newbie

Posts

Joined
Thu Aug 12, 2010 3:12 pm

Post by rph » Fri Jun 10, 2011 10:20 am

It's not OpenCart. You didn't set it up right somewhere. The code you wrote has a cache of 1 month. The code I gave you has a cache of 1 week. You have images that either aren't cached at all or are cached for 3.5 days.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by derek » Fri Jun 10, 2011 3:01 pm

I increased the 1 week to 5.

I'd really like to understand how you worked out this:
You have images that either aren't cached at all or are cached for 3.5 days. ?

Just in case Google PageSpeed is at fault, I also tried this site:
www.webpagetest.org/

It rates my front page 99/100 for leverage of browser caching. Maybe this indicates Google PageSpeed is a bit over zealous?

Newbie

Posts

Joined
Thu Aug 12, 2010 3:12 pm

Post by rph » Fri Jun 10, 2011 3:23 pm

You're right, I missed it by a factor of 10. It's 35 days.

I use the Page Speed plugin for Firefox. It can give you a report on all the individual resources.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by derek » Sat Jun 11, 2011 6:28 am

Thanks everyone for your help. I have put the above suggestions into place and am just ignoring the Google PageSpeed's comments.

Newbie

Posts

Joined
Thu Aug 12, 2010 3:12 pm
Who is online

Users browsing this forum: No registered users and 18 guests