Let Google host the jQuery of your Trac!


If you work on big amounts of content collaboratively, you might end up with hosting your own Subversion of Git repository with a Trac in your storeroom. Although Trac uses AJAX to make the sourcecode browser quite fast once the page is loaded, the first pageload can be relatively slow. This is especially annoying, when one is using another machine to present something or to dig something up for printing.


As we all know, there are very good reasons to let Google host jQuery for you. Unfortunately, Trac doesn’t support loading jQuery from Google and there does not seem to be a plugin for Trac doing this, either. But as long as .htaccess-files are enabled or — even better — Apache’s config-files can be changed, one can set up a redirect pointing to ajax.googleapis.com.


Add this line to your .htacces-file or to the apache configuration for every virtualhost with a Trac on it:

Redirect 301 <path to trac instance>chrome/common/js/jquery.js http://ajax.googleapis.com/ajax/libs/jquery/1.2/jquery.min.js

Where <path to trac instance> is the path to the trac instance relative to your domain. For example the mainpage of the wiki would be at http://example.com<path to trac instance>. Also note that requesting ajax.googleapis.com/[…]/1.2/jquery.min.js will give you the latest version of JQuery (1.2.x) that Google is hosting.


jQuery is currently about 30 KB in size. This means 56% of the pageweight in this case or — transferred over an ADSL connection with 1 MBit/s Upstream — over 1 second just for uploading jQuery. The whole page weighs in at about 53 KB distributed over 13 requests, which take about 2.7 seconds to load.

With the redirect applied, we see a „301 Moved Permanently“ in response to the request of the Trac’s jQuery and a new request to apis.google.com for jquery.min.js.

The first one only takes 12 ms in this case, because I am using the same internet connection as my server and all traffic only needs to travel trough my ISP’s routers and the response is very lightweight. With latencies typically not exceeding 60 ms, it should still be negligible when accessed via longer distance. The second attempt to get the jQuery takes only 78 ms of which the bigger part is due to network latency, because I redirected to the minified version of jQuery and google uploads at much faster rates than my server could via internet connection.

The page now loads in 1.7 seconds, almost 1 second or 36 % faster than before. The minified jQuery also causes the page to turn out about 13 KB or 24 % lighter.


Because Trac’s jQuery still needs to be requested in order to issue a redirect to GoogleAPIs, there is a „useless“ request now, which could be prevented by Trac issuing the „right“ request in the first place. The penalty for it is only one round-trip time and should therefore be negligible, though.


Schlagwörter: , , , , ,

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )


Verbinde mit %s

%d Bloggern gefällt das: