Need to set Apache cache for your website to improve performance? Our Developers can help you today.
Setting the Cache of your website determine how your Website visitor sees it on a web browser and this depends on how Apache's Mod_expires module is configured.
Here at Fixwebnode, as part of our Website Support Services, we regularly help our Customers to fix Apache and Website errors on a daily basis.
Today, we shall look into how to set caches with Apache Web Server.
More about Apache caches?
Caching via a Web Server is a method of enhancing the performance of a Server by allowing commonly requested content to be temporarily stored in a way that allows for faster access. This process speeds up processing and delivery of data by cutting out some resource intensive operations. Apache cache module allows you to cache data easily by means of shared memory.
How to configure caches with Apache?
To set caches with apache web server, you can configure the Cache-Control HTTP headers for your website.
To achieve this, you need to add "mod_expires" in the ".htaccess" file of your Website or server.
You can add the rules as shown below to your .htaccess file which is located in the root directory of your website. If this file does not exist, you can simply create one and add the line below;
This should be followed by the following rules;
ExpiresDefault "base[plus num type] [num type] ..."
ExpiresByType type/encoding "base[plus num type] [num type] ..."
This means that the ExpiresDefault and ExpiresByType directives is implemented which functions to allow Apache Expires Module to take effect.
The "ExpiresDefault" module helps to set caches for all files in the Server.
This module specifies the default algorithm meant to keep track of the expiration time relating to all the affected realm.
To set caches by type, use the "ExpiresByType" directive as seen on the directives above. This directive signifies the Expires header's value and the max-age directive available in the Cache-Control header generated for documents of a specified type.
Therefore, the "ExpiresByType" directive only takes effect when "ExpiresActive On" is implemented. Relatively, it overrides any expiration date set by "ExpiresDefault" when a specified MIME type is specified.
In the above directive, "base" belongs to;
ii. now (which is equivalent to "access")
"plus" there is an option feature.
"Num" represent an integer value working with atoi().
"Type" can be one of the following;
To set file types and times for caches, add the following directives to the .htaccess file;
# ExpiresByType text/html "access plus 900 seconds"
ExpiresByType text/css "access plus 60 days"
ExpiresByType image/gif "access plus 14 days"
ExpiresByType image/jpg "access plus 14 days"
ExpiresByType image/jpeg "access plus 14 days"
ExpiresByType image/png "access plus 14 days"
ExpiresByType application/x-shockwave-flash "access plus 14 days"
# Add a far future Expires header for fonts
ExpiresByType application/vnd.ms-fontobject "access plus 2 year"
ExpiresByType application/x-font-ttf "access plus 2 year"
ExpiresByType application/x-font-opentype "access plus 2 year"
ExpiresByType application/x-font-woff "access plus 2 year"
ExpiresByType image/svg+xml "access plus 2 year"
You can use the FilesMatch directive to implement cache for your files as shown below;
Header set Cache-Control "public"
Header set Cache-Control "public"
Header set Cache-Control "private"
Need support in fixing Apache Web Server Errors? We are available to help you today.