Ways to speed up your website performance

Many ways to speed up the website performance:-

1)Enable compression:

reduces the bandwidth of web pages, thereby reducing HTTP response. We can  do this with a tool called Gzip.

Gzip:  allows  web server to provide smaller file sizes which load faster for usage

For Apache:  use mod_deflate

Add the following content in apace2.conf for gzip compression-

<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist
# and the client accepts gzip.
RewriteCond "%{HTTP:Accept-encoding}" "gzip"
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA]

# Serve gzip compressed JS files if they exist
# and the client accepts gzip.
RewriteCond "%{HTTP:Accept-encoding}" "gzip"
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header append Content-Encoding gzip

# Force proxies to cache gzipped &
# non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>

2) Browser caching : Reduces the Bandwidth usage on both the user and server side and allows the page to load faster. Hence, the cache is especially useful when you have a slow or limited Internet connection.

Add the following content in apache.conf

<IfModule mod_expires.c>
ExpiresActive On
#ExpiresDefault A0

ExpiresDefault "access plus 2 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "now plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 600 seconds"
</IfModule>

<IfModule mod_headers.c>
<FilesMatch "\.(jpg|jpeg|png|gif|swf|txt|xml|js|css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(js)$">
Header set Cache-Control "max-age=604800, private"
</FilesMatch>
</IfModule>

-> enable mod headers by using
sudo a2enmod headers

-> restart apache by using
sudo service apache2 restart

-> enable mod expires by using
sudo a2enmod expires

->restart apache by using
sudo service apache2 restart

3)Minifying Resources

->Minifying Html
->Minifying Css
->Minifying Js
Reduces the size of page by eliminating extra spaces,line breaks and and indentation in your code so your pages are as lean as possible.

Leave a Reply

Your email address will not be published. Required fields are marked *