How to set cache Mode for wordpress & Joomla websites ?

Deal Score0
Free Search Engine Submission

People asked me , How to set cache for my website & how to increase page speed for my wordpress blog & joomla,drupal,magento websites & other html websites .

Google page speed will be increased ,if you implement this code in your website. You have to implement it correctly.

It was very easy ,Just add the below code to you .htaccess file in your file manager, you can add it anywhere , but don’t paste in middle of other codes.

The first code will set maximum duration & expire it in a time interval, it will cache ico|gif|jpeg|png|js|css files so your website loads faster.

### BEGIN Caching Code #########################
FileETag MTime Size
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
<FilesMatch “\.(ico|gif|jpe?g|png|js|css)$”>
ExpiresDefault “access plus 1 year”
</FilesMatch>
<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior.
ExpiresActive Off
</FilesMatch>
</IfModule>

i have set a 480 weeks for header cache, your logo & other header files will be cached for 480 weeks of duration.

# 480 weeks
<FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
Header set Cache-Control “max-age=290304000, public”
</FilesMatch>

The below code will cache xml & txt files for 2 days

# 2 DAYS
<FilesMatch “\.(xml|txt)$”>
Header set Cache-Control “max-age=172800, public, must-revalidate”
</FilesMatch>

The below code will cache html & htm files for 2 days

# 2 HOURS
<FilesMatch “\.(html|htm)$”>
Header set Cache-Control “max-age=7200, must-revalidate”
</FilesMatch>

The below code will compress your html,txt,php,js,css files to load better & faster.

<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>

### END Caching Code #########################

So The final code in you .htaccess file must be a combination of all codes.

### BEGIN Caching Code #########################
FileETag MTime Size
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
<FilesMatch “\.(ico|gif|jpe?g|png|js|css)$”>
ExpiresDefault “access plus 1 year”
</FilesMatch>
<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior.
ExpiresActive Off
</FilesMatch>
</IfModule>

# 480 weeks
<FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
Header set Cache-Control “max-age=290304000, public”
</FilesMatch>

# 2 DAYS
<FilesMatch “\.(xml|txt)$”>
Header set Cache-Control “max-age=172800, public, must-revalidate”
</FilesMatch>

# 2 HOURS
<FilesMatch “\.(html|htm)$”>
Header set Cache-Control “max-age=7200, must-revalidate”
</FilesMatch>

<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>

### END Caching Code #########################

Please follow and like us:
0
How to Start a Blog Bluehost
We will be happy to hear your thoughts

      Leave a reply