Skip to content

Use wp_enqueue_script_module instead of replacing the type on script_loader_tag #3225

@dilirity

Description

@dilirity

public function scriptLoaderTag( $tag, $handle = '', $src = '' ) {
if ( $this->skipModuleTag( $handle ) ) {
return $tag;
}
$tag = str_replace( $src, $this->normalizeAssetsHost( $src ), $tag );
// Remove the type and re-add it as module.
$tag = preg_replace( '/type=[\'"].*?[\'"]/', '', (string) $tag );
$tag = preg_replace( '/<script/', '<script type="module"', (string) $tag );
return $tag;
}

We ran into an issue where Jetpack Boost's concatenate JS feature was picking up modules and concatenating them with regular scripts.

Using wp_enqueue_script_module (it was introduced last year) would help separate the type of scripts enqueued on the page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions