Jump to content
Sign in to follow this  
Notretsam

Proper HTML caching

Recommended Posts

I know I do the cache via my .htaccess file but it seems like from my browser, that am caching to much.  always have about 500MB+ , which seems a lot , only started to happen after I set cache for my website.

I only want the images cached and below is what I have.  

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

I presume the type lines for css, pdf, javascript , shockwave-flash and x-icon  can be deleted?

 

am wondering about the ExpiresDefault line is needed?  

 

I also have the below coding, which I can't remember what it is for lol  I found it on the web, sure it was related to the internet cache.


<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

 <FilesMatch "\.(js|css|xml|gz)$">
  Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

 

Share this post


Link to post
Share on other sites
Quote

I presume the type lines for css, pdf, javascript , shockwave-flash and x-icon  can be deleted?

 

am wondering about the ExpiresDefault line is needed?  

Have you looked up what those do?

Quote

I also have the below coding, which I can't remember what it is for lol  I found it on the web, sure it was related to the internet cache.

It's not related to caching, look up mod_deflate if you want to see what it does.

Why exactly do you think you're caching too much?  How much should you cache?

Share this post


Link to post
Share on other sites
1 hour ago, justsomeguy said:

Have you looked up what those do?

I presume the cache items related to specific type, image/jpg would cache jpg images and so on with the others.  Since I only wanted to cache image files, presume the non image file extensions can be removed. 

1 hour ago, justsomeguy said:

It's not related to caching, look up mod_deflate if you want to see what it does.

ok so it resizes content and makes it smaller,  handy to have. 

1 hour ago, justsomeguy said:

Why exactly do you think you're caching too much?  How much should you cache?

don't have answer to these questions , which is why am on this forum asking.  just seems like a big jump in my chrome cache since i added this to my htaccess fille. 

Share this post


Link to post
Share on other sites

Well, it's really up to you to strike the balance that makes sense to you.  Either you use disk space to cache files that aren't going to change much, or you use time and bandwidth to transfer those files every time someone pulls up your site.  You can pull up your browser's developer tools and enable/disable the disk cache to see the balance that you're at.

Share this post


Link to post
Share on other sites

well after some thinking decided to remove the following lines and see how that goes

ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"

was hoping people on here would tell me what they would do. 

Share this post


Link to post
Share on other sites

I would cache everything that doesn't change often, that's what caching is for.  If your site is caching several hundred MB, then that's probably an indication that your site is too big, not that you should reduce caching.

Share this post


Link to post
Share on other sites

site is to big? as of right now, I can not see that being why, site is large but not a lot of images, css file is 27KB.

Maybe I am missing something that is causing it on website but doubt it.

I have cut back caching to just the image files and being waiting to see how it goes. 

Looks like it going be trial and error, just have to keep adding/removing a line and seeing how cache size is effected, was hoping not to take this long route.  

 

 

Edited by Notretsam

Share this post


Link to post
Share on other sites

You said it was storing "500+ MB" for the site, where is all of that space going?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×