Make a Lasting Impression

Join the Mailing List

Who's Online

21 user(s) are online (2 user(s) are browsing ImpressCMS Blog)

Members: 0
Guests: 21

more...
ImpressCMS proudly uses SourceForge
ImpressCMS on Ohloh.net
ImpressCMS Blog > Speeding up your site by using a CDN for Javascript files

Speeding up your site by using a CDN for Javascript files

Even in this time of rapid evolving browsers and almost unlimited bandwidth and throughput speed, the loading speed of a page is influenced heavily by the following two factors:
* how many files the browser needs to load to show your page (CSS and Javascript)
* Your physical distance from the content server

Browsers limit the amount of concurrent connections to the same server to download included files. Values range from 6 to 9 to 15, depending on your browser type and version. That will mean that if you include a lot of small files, the will be queued in some cases, leading to longer load times.

Even in this time of high-speed networks, added distance means added latency to you connections. When downloading many files, these added latencies can slow down your page loading.

You are maybe aware that Google has added the page loading speed as one of the metrics on which they base their ranking, so faster pages finish on top. Page speed is very important, and this is where CDN or Content Delivery Networks com into the picture. These networks are distributed globally, and aim at offering the best download speed for your location for certain heavily-used static files, such as Javascript libraries and site logo’s.

When you use a common CDN like the one offered by Google, you can get many versions of many widely-used javascript libraries from them at top speeds. If you want to use the same technique with files specific to your site, you will need to look at commercial options.

With a simple hack, we can add the use of CDN to our ImpressCMS site.

In header.php, find the following lines:

$xoTheme->addScript(ICMS_LIBRARIES_URL . '/jquery/jquery.js', array('type' => 'text/javascript'));
$xoTheme->addScript(ICMS_LIBRARIES_URL . '/jquery/ui/ui.min.js', array('type' => 'text/javascript'));

Replace that line with the following if you want to use the Microsoft CDN:
$xoTheme->addScript("http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js", array('type' => 'text/javascript'));
$xoTheme->addScript("http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.6/jquery-ui.min.js", array('type' => 'text/javascript'));

or if you’d rather have Google’s CDN:
$xoTheme->addScript("https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", array('type' => 'text/javascript'));
$xoTheme->addScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js", array('type' => 'text/javascript'));

Save the file, clear your cache, and voilà, you are using a CDN for your Javascript libraries.

This is a hack, so it will be gone every time you upgrade your ImpressCMS installation. It would be interesting to add this in a more generic way to the core in ImpressCMS 2.0. Have a look at ticket #603 on Assembla for that.
All posts by fiammybe
Subscribe to latest posts
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread