{"id":10758575,"date":"2018-10-08T03:58:25","date_gmt":"2018-10-08T03:58:25","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/handling-of-wp_add_inline_script\/"},"modified":"2018-10-08T03:58:25","modified_gmt":"2018-10-08T03:58:25","slug":"handling-of-wp_add_inline_script","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/handling-of-wp_add_inline_script\/","title":{"rendered":"Handling of wp_add_inline_script()"},"content":{"rendered":"<p>I&#8217;ve got a question\/request about how the plugin handles (or doesn&#8217;t handle) scripts added with <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_add_inline_script\/\"><code>wp_add_inline_script()<\/code><\/a>.<\/p>\n<p>I&#8217;ve got a few projects that include themes or plugins that use <code>wp_add_inline_script()<\/code> to add an inline portion of a script. Some of these are things I wrote, and others aren&#8217;t. These inline scripts typically depend on the script they were added for. So, as an example, the theme might load a carousel script, and then output the actual script that applies the carousel to a specific element with <code>wp_add_inline_script()<\/code>. <\/p>\n<p>The problem I&#8217;m having is that without &#8220;Aggregate inline JS&#8221; enabled, this results in the optimised JS file loading <em>after<\/em> the inline script that was output by <code>wp_add_inline_script()<\/code>. Since the inline script expected its dependency to already be loaded, this results in errors.<\/p>\n<p>Enabling &#8220;Aggregate inline JS&#8221; resolves the issue, because the inline parts are now included in the optimised script itself,  but now my cache is becoming enormous. Often in the Gigabytes.<\/p>\n<p>Is there anything the plugin can do to ensure that inline scripts added with <code>wp_add_inline_script()<\/code> are loaded after the optimised script that contains its dependencies?<\/p>\n","protected":false},"template":"","class_list":["post-10758575","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10758575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10758575\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=10758575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}