• I’ve got a question/request about how the plugin handles (or doesn’t handle) scripts added with wp_add_inline_script().

    I’ve got a few projects that include themes or plugins that use wp_add_inline_script() to add an inline portion of a script. Some of these are things I wrote, and others aren’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 wp_add_inline_script().

    The problem I’m having is that without “Aggregate inline JS” enabled, this results in the optimised JS file loading after the inline script that was output by wp_add_inline_script(). Since the inline script expected its dependency to already be loaded, this results in errors.

    Enabling “Aggregate inline JS” 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.

    Is there anything the plugin can do to ensure that inline scripts added with wp_add_inline_script() are loaded after the optimised script that contains its dependencies?

Viewing 1 replies (of 1 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    there’s no automagical solution I’m afraid, you can either;
    * keep “aggregate inline JS” on, excluding the inline JS that is busting your cache
    * or you can disable “aggregate inline JS” and exclude the JS that are needed early by the inline JS

    hope this helps,
    frank

Viewing 1 replies (of 1 total)

The topic ‘Handling of wp_add_inline_script()’ is closed to new replies.