Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Vite: ability to prevent preload tag generation from attribute resolver callback #45283

Merged
merged 3 commits into from Dec 15, 2022
Merged

[9.x] Vite: ability to prevent preload tag generation from attribute resolver callback #45283

merged 3 commits into from Dec 15, 2022

Conversation

daniser
Copy link
Contributor

@daniser daniser commented Dec 13, 2022

This PR adds an ability to return false from preload tag attribute resolver to prevent tag generation.
For example, this is needed when adding chunks generated by @vitejs/plugin-legacy
to stop preloading unneeded scripts in modern browsers.
Current code to do so looks like this:

Vite::withEntryPoints(['vite/legacy-polyfills-legacy', "resources/js/app-legacy.js", "resources/js/app.js"])
    ->useScriptTagAttributes(function ($src) {
        return Str::contains($src, '-legacy') ? ['type' => 'text/javascript', 'nomodule'] : [];
    })
    ->usePreloadTagAttributes(function ($src) {
        return Str::contains($src, '-legacy') ? ['rel' => 'dummy'] : [];
    });

Tag is still generating, but browsers omits it due to invalid rel attribute value.

With this PR, callback will look like this:

->usePreloadTagAttributes(function ($src) {
    return Str::contains($src, '-legacy') ? false : [];
});

This will suppress preload tag generation for all scripts which name ends with "-legacy".

@taylorotwell taylorotwell merged commit ab5cddb into laravel:9.x Dec 15, 2022
@daniser daniser deleted the feature/vite-suppress-preload-tags branch December 15, 2022 15:44
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.

None yet

2 participants