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

Option to be able to exclude preloads being injected into HTML #420

Closed
spacedawwwg opened this issue Aug 16, 2022 · 7 comments
Closed

Option to be able to exclude preloads being injected into HTML #420

spacedawwwg opened this issue Aug 16, 2022 · 7 comments
Labels
enhancement ✨ New feature or request

Comments

@spacedawwwg
Copy link

Description

Preloading everything (JS, CSS, Image assets) is bad for performance. It would be nice to have an option to prevent these being injected into the HTML, either as global toggle or on a file extension/mim-type basis.

We are currently doing this as a "post-build" task on statically generated pages, but this is not suitable for pages generated via SSR.

@spacedawwwg spacedawwwg added the enhancement ✨ New feature or request label Aug 16, 2022
@brillout
Copy link
Member

You'll be able to do that with #419 (comment).

Also, we should adjust vps's default behavior: what assets does vps currently preload that you think shouldn't?

@spacedawwwg
Copy link
Author

spacedawwwg commented Aug 19, 2022

You'll be able to do that with #419 (comment).

Also, we should adjust vps's default behavior: what assets does vps currently preload that you think shouldn't?

I don't think images should be preloaded at all (you can use attributes like loading and fetchpriority to achieve this). I'd say CSS shouldn't be preloaded either, devs can use other methods to load critical CSS.

preloading JS seems to be Vite's default, but I disagree with that too, I think any preload should be opt-in, not opt-out vitejs/vite#3133

@brillout
Copy link
Member

Why do you believe that? Happy to change my mind and with it vps's defaults.

@spacedawwwg
Copy link
Author

I suppose I'm looking at this from a website perspective over an 'app' perspective.

The fact that HTML is pre-rendered, the hydration is secondary and shouldn't block the page load.. especially if people are using lazy load strategies for some modules (e.g. using intersection observer)

https://www.debugbear.com/blog/rel-preload-problems

@spacedawwwg
Copy link
Author

I suppose the modulepreload's would be the only thing I'd consider keeping personally… but even then, as per my lazy-load reasoning, I'd have to run tests to see if preloading all the scripts upfront is less performant than just letting the modules do their round trips 🤔

@brillout
Copy link
Member

If the preload links are included at the end of the HTML, then I believe the initial render is not blocked by them.

That's why, so far, I think the current default is correct.

@brillout
Copy link
Member

https://vite-plugin-ssr.com/preload

Released in 0.4.52.

With that release, only font preload and modulepreload are injected by default. The rest is opt-in.

In case your company is up for it: https://github.com/sponsors/brillout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants