Book Image

Instant PageSpeed Optimization

By : Sanjeev Jaiswal
Book Image

Instant PageSpeed Optimization

By: Sanjeev Jaiswal

Overview of this book

PageSpeed is an important aspect of web design and site management. It is a Google measure of how well the site performs to technical measurements. PageSpeed can be measured using Google's own tool or a browser plugin. It is used to score sites in indices, and is important from a UI view as it forms a large part of the success of your site.Instant PageSpeed Optimization is a practical, hands-on guide that provides you with a number of clear, step-by-step exercises, which will help you to take advantage of the real power that is behind web optimization techniques, and give you a good grounding in using it in your websites.The book explores topics like HTML standards used for optimization, minifying scripts, and taking care of images, and solves the common errors that users do unknowingly. It will take you through a number of clear, practical recipes that will help you to take advantage of all the possible technologies to make your websitess efficient, fast, and accurate. You will not only learn basic standards to optimize your websites, but you will also learn some advanced level methods such as Apache handling, Flush methods, making AJAX cacheable, setting up browser caches, and reducing image size using CSS sprites. If you want to take advantage of all the necessary methods to make your website faster and efficient, then this book is a must-have.
Table of Contents (7 chapters)

Following HTML standards (Simple)


HTML is meant to display the data and you can code HTML in many ways, which will be rendered by different browsers in a different manner. So, we need some rules to be followed by all browsers to show the data uniformly. That's why we have World Wide Consortium (http://www.w3.org/) to handle this.

Getting ready

Web designers or developers should remain up-to-date with the latest technology and web standards, which include HTML5, CSS 3, JSON, and so on. Well, that doesn't mean you have to read every single specification line by line, but you will have to follow minimal web standard to achieve high percentage of uniformity of web standards over all the web browsers without losing your users.

How to do it...

If you are using HTML (not HTML5 for now), try to always write this line of code:

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">

Here, xmlns is the XML namespace and it should always have the value as http://www.w3.org/1999/xhtml. You can define in which language it should be rendered by setting the value of the lang attribute.

Put all the CSS files at the top under the head tag and try to move down all JavaScript at the bottom of the HTML code. CSS is required at the top for two reasons:

  • To have a presentational layout as it should be

  • So that it can be downloaded in parallel along with other HTTP requests

Use the tableless design whenever possible. The tableless forms may not make the page load faster but it will surely enhance the speed due to the following reasons:

  • Less number of DOM elements to be parsed

  • Layout being taken care by CSS

  • We can use the same CSS code for more tables if present, which would save a number of lines of code and would render faster

If you are good at CSS, converting HTML table elements into a CSS layout should be a cakewalk.

Check your W3C standard validity related to HTML, CSS (mainly), and load time on a regular basis.

We shouldn't leave back any error while writing tags. It should be properly closed and you should use proper tags for the specific purpose, for example, don't use the <b> tag to make the string bold, rather use <strong>. Use proper ending methods of one-sided tags, for example, <br /> instead of <br>. It would not make the site faster but will make parsing faster without any error.

We should avoid using inline JavaScript as much as possible and you should put external JavaScript files at the bottom of the HTML code. Because while downloading JavaScript files, it doesn't allow downloading anything else that will make the page load slower.

There's more...

You can follow HTML standards by analyzing errors and warnings caused by specific pages by using a Firefox add-on HTML Validator (https://addons.mozilla.org/en-us/firefox/addon/html-validator/). It has the option to check HTML and CSS validation separately online using a w3.org tool or by using W3C's free online validator tool (http://validator.w3.org/).

Results may vary from one tool to another due to analyzing error pattern difference. <br> may not be erroneous under HTML Tidy but it's an error under the W3C validator as it should be <br />.

In the following screenshot, you can see the result from HTML Validator for the URL www.packtpub.com:

While the following screenshot, shows the result from W3C's online validator for the same www.packtpub.com URL:

The preceding screenshot shows that there are 27 errors and 2 warnings that exist and should be taken care of.

Try W3C's online validator for your own website and try and fix all the errors and warnings shown by this tool.