When adding inline JavaScript, it doesn't aggregate the inline script tags that are beside each other together. Doing this will mean less HTML on the page, meaning a performance boost for inline JavaScript when the parser when its reading through the HTML....
Take a look at the following use case:
drupal_add_js('(function($){alert("Weight 0 #2");})(jQuery);', array('type' => 'inline', 'scope' => 'footer'));
drupal_add_js('(function($){alert("Weight -8 #1");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -8));
drupal_add_js('(function($){alert("Weight -8 #2");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -8));
drupal_add_js('(function($){alert("Weight -8 #3");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -8));
drupal_add_js('http://example.com/example.js?Weight -5 #1', array('type' => 'external', 'scope' => 'footer', 'weight' => -5));
.... You will get:
<script type="text/javascript">
<!--//--><![CDATA[//><!--
(function($){alert("Weight -8 #1");})(jQuery);
//--><!]]>
</script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
(function($){alert("Weight -8 #2");})(jQuery);
//--><!]]>
</script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
(function($){alert("Weight -8 #3");})(jQuery);
//--><!]]>
</script>
<script type="text/javascript" src="http://example.com/example.js?Weight -5 #1"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
(function($){alert("Weight 0 #2");})(jQuery);
//--><!]]>
</script>
It should really aggregate those inline JavaScript tags when it can so that we end up with the following much cleaner HTML instead:
<script type="text/javascript">
<!--//--><![CDATA[//><!--
(function($){alert("Weight -8 #1");})(jQuery);(function($){alert("Weight -8 #2");})(jQuery);(function($){alert("Weight -8 #3");})(jQuery);
//--><!]]>
</script>
<script type="text/javascript" src="http://example.com/example.js?Weight -5 #1"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
(function($){alert("Weight 0 #2");})(jQuery);
//--><!]]>
</script>
Three script tags instead of five.
Comments
Comment #1
mfer commentedsub.
Comment #2
effulgentsia commentedSubscribe. Will look at more thoroughly later. Though I really wonder if we should instead setup a render array for consistency with drupal_get_css() and our general approach to rendering in D7.
Comment #3
robloachTagadelic!
Comment #4
retester2010 commentedaggregateinline.patch queued for re-testing.
Comment #6
nod_Comment #7
robloachComment #8
nod_Inline JS is not possible anymore through the API (can still generate markup and have JS in it).