Skip to content

Bug with wp_add_inline_script #55

@emrikol

Description

@emrikol

This is a fun edge case bug:

When a script ("child") is concatenated with another script that it requires ("parent"), but also uses wp_add_inline_script() with the third argument being before, any code that has dependencies on the parent script will fail.

Just as an example:

  1. The Shortcake plugin registers select2 with a dependency on jQuery
  2. It then adds an inline script that depends on jQuery, but wants it output before the select2 JS file.
  3. The nginx-http-concat plugin will output the before script
  4. The nginx-http-concat plugin will output the concatenated blob
  5. If the parent and child script are in the same blob, the before JS will fail.

I believe what needs to be done is to check if a script has a wp_add_inline_script() with a before , it would be good to break the blob apart at that exact script, output the inline script, and then the concatenated blob.

We could get more detailed and check if any parent/child dependencies exist within the same blob first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions