Theming: Best practices

by Gisle Hannemyr

TBA.

Table of contents

Introduction

[TBA]

See: High Performance Web Sites.

List

Use a CDN for client side assets

A content delivery network (CDN) is a collection of web servers distributed across multiple locations to deliver content to users more efficiently.

The upfront advantage of a CDN is that is probably closer to the user than your server, and has more bandwidth.

But in addition, many JQuery libraries are widely deployed and are cached by the user's browser. This means the JQuery may already be cached due to some other site the user has visited. If the URL is the same, the JQuery will not be downloaded again and a duplicate cached when the user visits your site.

Widely used CDNs are:

Load JavaScript in the footer

The browser will stop rendering the page until each block of JavaScript it encounters has been executed. For small scripts, this isn't a big problem. However, for large JavaScript libraries, the pauses may become noticable.

By loading JavaScript in the footer, you can access the DOM without having to call a document.ready() function. When the page render finally makes it down to your JavaScript code, then all the other page elements have usually loaded already.

If you include JavaScript files at the bottom of your page, you give the priority of your HTTP requests to the visual display that will be presented to the user instead of to the logic of interaction or dynamics. I believe, if you do not use a content delivery network to deliver images to the client then you are only allowed to process a maximum of 2 HTTP requests at a time. You do not want to waste these requests on logic because we all know how impatient the end user is.

Final word

[TBA]


Last update: 2015-09-15 [gh].