Leverage browser caching

Hello,

I am running Google's PageSpeed test and am coming up with:

Leverage browser caching

Everything I am finding is not clear to me.  The site is on an Apache server and I have the expire and header modules running.

Please advise.

Have a great day,

Don
GEMCCAsked:
Who is Participating?
 
Mohamed MagdyCTOCommented:
Google PageSpeed test will drive you insane, Google itself not following PageSpeed guidelines.

I tried everything to get at least 95/100 but no luck, although I'm using mod_pagespeed in apache and I've enabled filters, installed mod_deflate, mod_expires and mod_gzip, installed Caching system, made another server just for caching.

All of that wasn't enough for Google PageSpeed, still telling me that I need to cache request although they are cached completely. so I gave up testing using it, Do the next steps and you will be good to go:

1- Minify JS, CSS, HTML.
2- Compress images using any compressor tool (I can't provide a link due to guidelines).
3- Install mod_pagespeed for Apache and enable CoreFilters.
4- Use mod_deflate, mod_expires and mod_gzip in .htaccess, I use the following for a WordPress blog:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png
</IfModule>
## EXPIRES CACHING ##

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

Open in new window

5- Install any caching system beside mod_pagespeed like xCache or EAccelerator or MemCached.

Then you are good to go.

Hope this helps you.
0
 
Ray PaseurCommented:
You may also want to consider adding an expiration on the server so you can send a 304 header for resources that have not changed.  For example, your server does not need to send the same picture over and over again - just tell the browser that the last copy is still OK.
0
 
GEMCCAuthor Commented:
Hello,

I got everything installed and working and it sped things up a lot!

One thing I am not sure about, if I understand correctly, step 4 is a config for WordPress.  I am not using WP so where would I place this code/script?

Have a great weekend,

Don
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Mohamed MagdyCTOCommented:
Step 4 can be made with any type of websites that's why I copied it over to you as it will cache CSS, images, JS, icons and PDF.
0
 
GEMCCAuthor Commented:
Understood, but where do I put the code/script?
0
 
Mohamed MagdyCTOCommented:
In a file called .htaccess beside your website files in the same folder.
0
 
GEMCCAuthor Commented:
Gotcha, there is not an .htaccess file in the same directory as the web files.  Should I just create one and copy your info?
0
 
GEMCCAuthor Commented:
Still waiting on an answer regarding not having an .htaccess file.  Please advise.

In the meantime, I see what you mean, the PageSpeed test fluctuates by 10+ points even if I have not made any changes!

Please let me know about the .htaccess file.

Have a great day,

Don
0
 
David Johnson, CD, MVPOwnerCommented:
yes create one and put it in your website root folder
0
 
Mohamed MagdyCTOCommented:
I'm so sorry I was out of town, yes as David said, create one in your website root folder and put info inside it.
0
 
GEMCCAuthor Commented:
Hello,

I created the .htacces file and added the code you provided, but still the same issue.

Please advise.

Have a great day,

Don
0
 
Mohamed MagdyCTOCommented:
When you open Leverage browser caching in PageSpeed, what URLs are you seeing? Are they external links? because if their were external links you can't cache them.

The code I provided will cache local files but it won't cache external links.

You can find the result of PageSpeed on my website in an attached image, you can find in it that the un cached links are all external.
2015-05-07-11-30-04.png
0
 
Mohamed MagdyCTOCommented:
FYI, external links are cached from the external source and it's not possible to cache them until you serve them locally.
0
 
GEMCCAuthor Commented:
Hello,

The ones I am seeing are PNG files are supposedly not being cached, but your code has PNG set.

Please advise.

Have a great weekend,

Don
0
 
Mohamed MagdyCTOCommented:
Could you please post a screenshot of the links?
0
 
GEMCCAuthor Commented:
Well, actually, now it is all cleared up!  I guess it took a while.

Thanks for your help,

Don
0
 
GEMCCAuthor Commented:
Resolved issue.
0
 
Mohamed MagdyCTOCommented:
That's nice to hear, you welcome anytime :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.