File caching to speed up websiteFile Caching is an important step to Speed Up Website and Web Page Load Time.
There are many factors influence the speed of your website. The faster your website or web page loads the more happier your readers will be.

There are many different and important things required to do to make your website faster. We have already discussed many methods to improve the server response time or to speed up the website. We also discussed about the tools to check your Website / Web page Load Speed.
File caching is one of the most important steps towards an optimized website. It is a major stepping stone to speed up website. If cached, the documents and files may be fetched from the cache rather than from the source until this time has passed. If your files are not changing frequently like images or script files you can set a maximum expiry date so that whe user requests for a web page in your site, the page will load faster since it is already available in the cache.
If your website is hosted on Apache web Server then file caching is simple to achieve.
There is a simple global configuration file name .htaccess file in Apache. To know more >> .htaccess Tutorial -A guide and .htaccess tricks and tips.

How to achieve file caching using .htaccess file

Apache server provides different functionalities through configured modules. There are two different Apache modules available to configure caching. They are mod_expires and mod_headers. Today we will discuss more about module mod_expires.

Caching using Apache Module mod_expires

Apache provides Module mod_expires for the generation of Expires HTTP headers according to user-specified criteria.
You can configure this module directives inside directive. The mod_expires module provides three directives as below

ExpiresActive directive

This directive enables or disables the generation of the Expires header for the document realm in question.If set to Off, no Expires header will be generated for any document in the realm.So we need to set ExpiresActive ON.

ExpiresByType directive

This directive defines the value of the Expires header generated for documents of the specified type.
For example “ExpiresByType image/gif A2592000” indicates that expire GIF images after a month in the client’s cache.
Or “ExpiresByType text/html M604800
Here “M’ means that the file’s last modification time should be used as the base time and “A” indicates client’s access time should be used

The time that can be used is mentioned below.
.htaccess Time examples

1
2
3
4
5
6
7
300	 5 Minute
3600	 1 Hour
86400    1 DAY
259200   3 DAY
604800   1 WEEK
2419200  1 MONTH
29030400 12 MONTH

ExpiresDefault directive

This directive sets the default algorithm for calculating the expiration time for all documents in the affected realm.For example, any of the following directives can be used to make documents expire 1 month after being accessed, by default:
ExpiresDefault “access plus 1 month”

The example given below gives a complete picture on how to achieve Caching using Apache Module mod_expires

1
2
3
4
5
6
7
8
9
# Begin Cache Control
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
</IfModule>

We will discuss about achieving caching using the mod_headers module in the next post.

Sign up for our newsletter to receive great articles!
Placeholder Placeholder
Binu GeorgeWebsite OptimizationApache Modules,Cache-control,css caching,ExpiresDefault,file caching,htaccess,htaccess Caching,if-modified-since,javascript caching,max-age,mod_expires,mod_headers,must-revalidate,optimize website,speed up website,speed website,website cachingFile Caching is an important step to Speed Up Website and Web Page Load Time. There are many factors influence the speed of your website. The faster your website or web page loads the more happier your readers will be. There are many different and important things required to do to...Tech-Knowledge that helps