Download & Extend

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

Project:AdSense
Version:6.x-1.2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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

Comments

#1

I guess that the new Asynchronous Tracking code will solve your issues when it will be integrated in the Adsense module. The new Asynchronous Tracking does not need to be loaded in the footer.

See: #649734: Add new Google Adsense Asynchronous Tracking code

#2

Status:needs review» fixed

Hi,

This has nothing to do with the Asynchronous Tracking code.. And indeed, it would be better to take advantage of Drupal's Javascript optimizations..

I have committed your patch to CVS. Thanks!

João

#3

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here