Skip to content

feat: Allow args to be passed to registered scripts#7

Open
joezappie wants to merge 1 commit intotailpress:mainfrom
joezappie:main
Open

feat: Allow args to be passed to registered scripts#7
joezappie wants to merge 1 commit intotailpress:mainfrom
joezappie:main

Conversation

@joezappie
Copy link

wp_enqueue_script allows for optional arguments to be passed to change the behavior of the included scripts. This pull request adds support to be able to pass those, allowing scripts to be defer, async or change if its enqueued in the footer. This allows for greater control and optimizations for page speed metrics.

Usage

Takes the same parameters as the wp_enqueue_script function:

$compiler->registerAsset( 'resources/js/app.js', args: [ "strategy" => "defer" ] )

If no argument is provided, it defaults to true (see notes).

Notes

The Vite compiler and Laravel had different defaults for the 5th parameter. Laravel was set to false and Vite was set to true. This defaults both to true at the moment.

Tested and working with ViteCompiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant