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.

CommentFileSizeAuthor
aggregateinline.patch3.98 KBrobloach

Comments

mfer’s picture

sub.

effulgentsia’s picture

Subscribe. 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.

robloach’s picture

Issue tags: +JavaScript

Tagadelic!

retester2010’s picture

Issue tags: -JavaScript

aggregateinline.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +JavaScript

The last submitted patch, aggregateinline.patch, failed testing.

nod_’s picture

Version: 7.x-dev » 8.x-dev
robloach’s picture

Assigned: robloach » Unassigned
nod_’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Inline JS is not possible anymore through the API (can still generate markup and have JS in it).