AdSense Click: JavaScript should not be forced to load in footer (patch attached)

andrewsuth - October 16, 2009 - 15:22
Project:AdSense
Version:6.x-1.2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I was front-end optimizing my site and was finding that when I optimized my javascript, it was creating 2 x JS files and not just 1:

  • 1 x adsense_click.js
  • 1 x JS from all other modules

This was having a performance impact due to the additional HTTP request to retreive the lonely adsense_click.js file. It also created an additional issue when minifying the js.

After investigating, I found that the AdSense Click mini-module was using hook_footer to inject the HTML script into the end of the page.

I think a better solution would be to use hook_init and add the JS using the drupal_add_js function. This way you can group my JS files all in the same location (header, footer, or whatever I choose is best) and can successfully optimize and minify all JavaScript files together (rather than being left with a rogue JS files which slows page loads down).

I have attached a patch for adsense_click.js which takes care of this performance issue.

AttachmentSize
adsense_click.patch1.17 KB
 
 

Drupal is a registered trademark of Dries Buytaert.