Basically, all the files your site uses (jpgs, gifs, css, js, etc) need to be able to tell visitors computer how long they should keep them for before checking for a new file. This is called web browser caching. If we don't specify the browser a "cache time" then it will get a new copy of the file every time they visit the site which means more bandwidth usage and increases your page load speeds.

Google Page Speed recommends that files are cached at least a month. If you don't make many changes, set it to at least a month. However, if you make changes to your site or are still working on developing the site, you may want to set your JS and CSS files to something lower such as 24 hours. However, in the example below we have set the caching of all files to 5 weeks.

To leverage web caching you will have to add some lines of code to your .htaccess file in the root folder of your OpenCart installation.

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

# Set up caching on media files for 5 weeks
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A3024000
Header append Cache-Control "public"
</FilesMatch>

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

# Set up 5 week caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A3024000
Header append Cache-Control "proxy-revalidate"
</FilesMatch>

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

If you need further assistance please feel free to ask a question on our support center.

Continued Education in Course OpenCart
You are viewing Section 41: 318: Using web browser caching in OpenCart
Section 40: 319: Using a Subdomain to store your images in OpenCart
Section 42: 317: Enabling GZIP compression in OpenCart
Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!