Skip to content

Non-modern build should also ("pre")load CSS #9902

@Tal500

Description

@Tal500

Description

While I'm doing my efforts in sveltejs/kit#6265 to add legacy support to SvelteKit on the Vite way, I had noticed that when navigating from one page to the other, the internal function __vitePreload is called, which is defined in the plugin importAnalysisBuild.

As far as I understand, the purpose of this function is to preload JS modules and also to (pre?)load CSS files.
On legacy output chunks, it shuts down the preloading ability.
I understand that there is no need to preload JS modules on non-modern(i.e. non ESModule compatible) browsers, but for the correct way of loading CSS, the CSS files should(?) be loaded in __vitePreload.

According to my local tests, if the CSS are getting preloaded on legacy builds, everything works great in my legacy work on SvelteKit.

Suggested solution

Change the code of the plugin importAnalysisBuild to (pre?)load CSS anyway, and when the browser is also modern, import also the preloaded JS files.

Alternative

You tell me?

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions