Fix inline scripts breaking when using jQuery on empty source scripts #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Expected/Desired Behavior
Scripts registered/enqueued without a source should add inline scripts after jQuery has been loaded.
Actual Behavior
Registering a dummy script without a
src
and using wp_add_inline_script() adds to DOM before jQuery is loaded.For example, the plugin PublishPress Capabilities registers a dummy script to attach an inline script using jQuery: https://github.com/publishpress/PublishPress-Capabilities/blob/06000a5be5f896e0f3cdcbe3990afe9310243e90/includes/functions-admin.php#L266-L271
The current logic processes empty src scripts before jQuery is defined. This PR adds an extra check within the first group definition to not process scripts that contain inline content, which is also later checked at line 113:
nginx-http-concat/jsconcat.php
Lines 113 to 115 in 73dbe08
Steps to Reproduce
Add this code to your theme to register a dummy script with an inline jQuery script:
Load a page on the frontend and check browser dev tools to find the
jQuery is not defined
error.