question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prevent loading global style entry css file

See original GitHub issue

We now have styles inlined in the page (https://github.com/nuxt/framework/pull/7160), and we’ve switched the global CSS file to a non-blocking prefetch. However, the vite preloader does still add these styles to the page, and we can probably avoid this (or have an option to avoid this).

Note: this may be unfeasible as entry.css may include more CSS than is inlined in the page, and be necessary for subsequent navigation. See https://github.com/nuxt/framework/issues/7623 for example.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Anoesjcommented, Nov 3, 2022

@danielroe below are two URLs.

Old URL (without our hook) and this new URL (with our hook). Both URLs have exact same code except the hook above.

The way entry.css is added is still a blocking request (at least in Chrome). <link rel="prefetch stylesheet" href="/_nuxt/entry.c5c3adc4.css">

We may modify it as follows (source) <link rel="stylesheet" href="/_nuxt/entry.c5c3adc4.css" media="print" onload="this.media='all'; this.onload=null;">

I can’t find source but I have read somewhere that above might interfere with Content Security Policy (CSP). I am not sure about proper solution for this but if the css continues to be blocking, inline css is useless. Alternately, we might try adding css to early hints.

This change depends on JavaScript to load styles. Therefore, generated builds don’t load this CSS file and styling breaks when JS is disabled. Can you take another look at another possible solution that doesn’t require JavaScript to be enabled to make sites look like they should? 😄

Also, when JavaScript is enabled, there’s a flash of unstyled elements with this solution. It doesn’t look nor feel right!

3reactions
jguptacommented, Sep 20, 2022

@danielroe below are two URLs.

Old URL (without our hook) and this new URL (with our hook). Both URLs have exact same code except the hook above.

The way entry.css is added is still a blocking request (at least in Chrome). <link rel="prefetch stylesheet" href="/_nuxt/entry.c5c3adc4.css">

We may modify it as follows (source) <link rel="stylesheet" href="/_nuxt/entry.c5c3adc4.css" media="print" onload="this.media='all'; this.onload=null;">

I can’t find source but I have read somewhere that above might interfere with Content Security Policy (CSP). I am not sure about proper solution for this but if the css continues to be blocking, inline css is useless. Alternately, we might try adding css to early hints.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure global css and sass stylesheet with webpack ...
I finally make it work. So here is the changes I made: 1) The path to style.css is now ignored in css/scss clauses....
Read more >
css-loader | webpack - JS.ORG
file.js import css from "file.css";. webpack.config.js ... Styles can be locally scoped to avoid globally scoping styles. The syntax :local(.
Read more >
How to configure CSS Modules for webpack - LogRocket Blog
Increase the flexibility of your app's CSS components with CSS Modules and Webpack in this handy tutorial and demo app build.
Read more >
How to configure CSS and CSS modules in webpack
The first thing we are going to do is to add a styles.css file in the project. ... When css-loader sees this line,...
Read more >
Angular Global CSS styles - TekTutorialsHub
We will also learn how to add custom CSS files & external style sheet to angular application.. Table of Contents. Example Application; Adding ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found