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

Deferred JS that bundles CSS blocks rendering. #2576

Open
jonnyarnold opened this issue Jan 24, 2019 · 1 comment
Open

Deferred JS that bundles CSS blocks rendering. #2576

jonnyarnold opened this issue Jan 24, 2019 · 1 comment

Comments

@jonnyarnold
Copy link

jonnyarnold commented Jan 24, 2019

First of all - thanks for Parcel, I'm having a great time with it!

I'd like to show a "Loading" indicator on my page while my main application is being loaded:

index.html

<body>
  <p>Loading...</p>
  <script defer src="./app.js"></script>
</body>

app.js

import * as React from "react"
import css from "./style.css"
// ...

style.css

.app {
  margin: auto;
}

When Parcel compiles index.html, it injects an extra CSS tag for the deferred JavaScript. Because CSS blocks rendering of the page, the Loading indicator is never shown.

Current Behaviour

When compiled, index.html looks like this:

<head>
  <link rel="stylesheet" href="123.css" />
</head>
<body>
  <p>Loading...</p>
  <script defer src="./app.js"></script>
</body>

🤔 Expected Behavior

For deferred JavaScript, CSS tags should be added asynchronously:

<head>
  <link rel="preload" href="123.css" as="style" />
</head>
<body>
  <p>Loading...</p>
  <script defer src="./app.js"></script>
</body>
@jonnyarnold
Copy link
Author

I've done a little bit more digging on this and it looks like rel="preload" isn't supported by all browsers, so we might have to use loadCSS for this instead of the example given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants