How to optimize webpage by Google Page Speed Suggestions

Sometimes we need to optimize our developed webpages. Today I will show you how to optimize your web pages with compression, minifying css/javascript, leverage browser caching and other suggested method provided by Google Page Speed?.

I am describing you about few suggestions provided by Google Page Speed and how you can optimize your web pages.

Compress website resources

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

The above file should be write inside .htaccess file in your root directory of your website. The above code will compress your content (i.e: Html, JavaScript) and everything by using DEFLATE module of Apache. Just make a new file and rename it with .htaccess?and copy/paste the above code inside your website’s .htaccess? file.

Expiration date set in Header output of Resources

It’s also very much important to set Expiration Date to each of the resources which are cache-able. Just place the following code inside your .htaccess file.

<IfModule mod_expires.c>

# Enable expirations
ExpiresActive On

# Default directive
ExpiresDefault "access plus 1 month"

# My favicon
ExpiresByType image/x-icon "access plus 1 year?

# Images
ExpiresByType image/gif "access plus 3 month"
ExpiresByType image/png "access plus 3 month"
ExpiresByType image/jpg "access plus 3 month"
ExpiresByType image/jpeg "access plus 3 month"

# CSS
ExpiresByType text/css "access 3 month?

# Javascript
ExpiresByType application/javascript "access plus 1 year"

</IfModule>

The above code will set expiration date for all of your resources in your websites. It will increase speed of your website effectively.

Connection: Keep-alive in Apache?

Keeping connection alive will do a great and big thing to optimize your web page. It will make consistent connectivity with server for rendering scripts and many other resources. So add the following lines inside your .htaccess? file.

#Connection keep alive
#Page Speed Optimize tutorial by Shaharia Azam (shaharia.azam@gmail.com)
<ifModule mod_headers.c>
    Header set Connection keep-alive
</ifModule>

The above codes will do a great things which will optimize your web pages for your visitors. It’s very important for developing large web pages. You can test your site’s performance from Google Page Speed online.

Shaharia is a professional software engineer with more than 10 years of experience in the relevant fields. Digital ad certified, cloud platform architect, Big data enthusiasts, tech early adopters.