Habari Plugins: Cache Gists and an Update to Google Analytics

tags: , , , ,

As of last night, this site is run­ning on Habari again (from Dru­pal, from Nis­aba, from Habari…). I am using quite a few plu­g­ins for site opti­miza­tion — here are two. The Google Ana­lyt­ics plu­gin is orig­i­nally by Gra­ham Chris­tensen, the Cache Gists plu­gin is my own cre­ation. Both of these plu­g­ins were tested with ver­sion 0.6 of Habari.

Google Ana­lyt­ics

Drupal’s Google Ana­lyt­ics plu­gin had the use­ful abil­ity to cache the ana­lyt­ics javascript file, which reduces the num­ber of DNS lookups for vis­i­tors brows­ing your site. I decided to get my hands dirty, and added this option to the Google Ana­lyt­ics plu­gin from the Habari Extras repository.

While I was at it, I added https detec­tion to the plu­gin. Stock Google Ana­lyt­ics code writes the script tag to the doc­u­ment after the page is loaded, but there are mul­ti­ple issues with this fea­ture, the pri­mary one being that it doesn’t play nice with real XHTML doc­u­ments. The Google Ana­lyt­ics plu­gin now writes the script loca­tion into the doc­u­ment before send­ing it to the client.

Down­load here: googleanalyticsextra-0.6 – 0.0.1.zip

Update 04.25.2009: Changes have been merged into the Google­An­a­lyt­ics plu­gin at Habari Extras.

Cache Gists

Sim­i­larly to the Google Ana­lyt­ics stock code, GitHub Gists are inserted into the doc­u­ment using document.write(). Unlike Google Ana­lyt­ics, Gists are usu­ally right in the mid­dle of page con­tent, mak­ing doc­u­ment ren­der­ing jerky. This plu­gin caches the Gist to the web­server, avoid­ing document.write(). I pub­lished a pre­vi­ous entry about GitHub Gists here.The tar­get audi­ence for this one will be a small niche for sure, but here it is.

Down­load at Github

Future Updates

At some point, I may add the option to move the Gist stylesheet to the doc­u­ment head (if that’s pos­si­ble) or strip the Gist stylesheet from page to allow for eas­ier cus­tom styling. Also, I’d like to look into cre­at­ing a minify plu­gin for Habari. Stay tuned!

Feedback

Owen

Need a minify plu­gin? Improve on this one:

http://​trac​.habaripro​ject​.org/​h​a​b​a​r​i​-​e​x​t​r​a​s​/​b​r​o​w​s​e​r​/​p​l​u​g​i​n​s​/​j​s​m​i​n​c​d​n​/​t​r​u​n​k​/​j​s​m​i​n​c​d​n​.​p​l​u​g​i​n.php