I found a problem while testing my site with Firefox addon "Page Speed" :
http://code.google.com/speed/page-speed/

Here is reported optimization error :

Optimize the order of styles and scripts:
The following external CSS files were included after an external JavaScript file in the document head.
To ensure CSS files are downloaded in parallel, always include external CSS before external JavaScript.

And in HTML source code I found that:

<script type='text/javascript' src='http://www.example.com/openx/www/delivery/spcjs.php'></script> 
<link type="text/css" rel="stylesheet" media="all" href="/drupal/modules/book/book.css?V" />
<link type="text/css" rel="stylesheet" media="all" href="/drupal/modules/node/node.css?V" />
...
<link type="text/css" rel="stylesheet" media="all" href="/drupal/sites/all/modules/cck/theme/content-module.css?V" />
<link type="text/css" rel="stylesheet" media="all" href="/drupal/sites/all/modules/dhtml_menu/dhtml_menu.css?V" />
<script type="text/javascript" src="/drupal/sites/all/modules/jquery_update/replace/jquery.min.js?V"></script>
<script type="text/javascript" src="/drupal/misc/drupal.js?V"></script>
...
<script type="text/javascript" src="/drupal/sites/all/modules/rounded_corners/jquery.corner.js?V"></script>
<script type="text/javascript" src="/drupal/sites/all/themes/artisteer/script.js?V"></script>

Why OpenX javascript tag is the only one before CSS tags ?
Maybe it is not included in page in the best manner.

Comments

srobert72’s picture

file : openx.inc
line : 45
OpenX module writes this HTML peace of code :

<script type='text/javascript' src='{$url}'></script>

I think we should use this PHP Drupal code :

drupal_add_js('{$url}');

See : http://api.drupal.org/api/function/drupal_add_js

srobert72’s picture

OK I made a mistake, it's not possible for external JavaScript in Drupal6 with this function API.
See #91250: JavaScript Patch #4: External Scripts

Other solution in this comment : http://drupal.org/node/91250#comment-640811

Line 45 : delete this code :

\n<script type='text/javascript' src='{$url}'></script>

And new line add this code :

drupal_add_js('</script><script type="text/javascript" src="'.$url.'" >', 'inline');

So old code :

  $spc_code .= "  }\n// ]]> --></script>\n<script type='text/javascript' src='{$url}'></script>";

  drupal_set_html_head($spc_code);

becomes

  $spc_code .= "  }\n// ]]> --></script>";

  drupal_add_js('</script><script type="text/javascript" src="'.$url.'" >', 'inline');
  drupal_set_html_head($spc_code);

I've just tested it and it works fine.

WildBill’s picture

From my days working in the ad trafficking department of an online publisher not too long ago, I remember that it was very important that the ad (and hence the javascript) gets called as quickly as possible when the page loads. You could almost argue that it should be called before anything else. The reason for this is that because users often click to other pages or close windows, if the ad is not called quickly enough, it might not get a chance to load at all before the page is gone. This causes high discrepancies when the publisher (the Drupal site) counts as an ad as having been served, but the ad server (the advertiser's server) says it didn't serve because they didn't get a chance to fully load their ad tag. There is a lag between when Drupal counts the ad, and when the advertiser's server counts the ad as fully served. This is made worse when the javascript loads late. So that's my guess as to why the creators of this module put the javascript so high on the page, to reduce discrepancies and increase the likelihood of every possible ad being served & counted.

wuinfo - bill wu’s picture

Category: Bug report » Feature request
Issue summary: View changes

It is not a bug but a feature request.