16.03.2017 Views

Learning HTTP/2

akamai-learning-http2-preview-edition

akamai-learning-http2-preview-edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1. Revisit their usage periodically. Over time, it is likely the web page keeps downloading<br />

some JS that may no longer be needed, and removing it is the fastest and<br />

most effective resolution path!<br />

2. If the JS execution order is not critical and it must be run before the onload event<br />

triggers then set the “async” attribute, as in .<br />

This alone can improve your overall user experience tremendously, by downloading<br />

the JS in parallel to the html parsing. Watch out for document.write<br />

directives as they would most likely break your pages, so test carefully!<br />

3. If the JS execution ordering is important and you can afford to run the scripts<br />

after the DOM is loaded, then use the “defer” attribute, as in <br />

4. If the js is not critical to the initial view, then you should only fetch (and process)<br />

the js after the onload event fires.<br />

5. You can consider fetching the JS through an iframe if you don’t want to delay the<br />

main onload event, as it’ll be processed separately from the main page. However<br />

JS downloaded thru an iframe may not have access to the main page elements.<br />

If this sounds a tad complicated, it is because there is no one-size-fits-all to this problem,<br />

and it can be hazardous to recommend a particular strategy without knowing<br />

the business imperatives and the full html context. The list above though is a good<br />

starting point to ensure that no JS is left blocking the rendering of the page without a<br />

valid reason.<br />

Optimize images<br />

The relative and absolute weight of images for the most popular web sites keeps<br />

increasing over time. The Figure below is taken from httparchive.org and shows the<br />

number of requests and bytes size per page over the years.<br />

Best Practices for Web Performance | 19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!