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

How to optimize too many css requests #6528

Closed
1 task
J-env opened this issue Mar 13, 2023 · 5 comments
Closed
1 task

How to optimize too many css requests #6528

J-env opened this issue Mar 13, 2023 · 5 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: styling Related to styles (scope)

Comments

@J-env
Copy link

J-env commented Mar 13, 2023

What version of astro are you using?

2.1.2

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm,pnpm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

image

Link to Minimal Reproducible Example

https://docs.astro.build/en/getting-started/

Participation

  • I am willing to submit a pull request for this issue.
@bluwy
Copy link
Member

bluwy commented Mar 13, 2023

This usually happens when the component is shared among many places that the CSS get chunked like so, but that looks a bit extreme, if you can provide a repro of how to re-create this (stackblitz/codesandbox/etc), that would be great.

@bluwy bluwy added the needs repro Issue needs a reproduction label Mar 13, 2023
@delucis
Copy link
Member

delucis commented Mar 14, 2023

That’s the CSS built in the docs site output 😅

@bluwy
Copy link
Member

bluwy commented Mar 14, 2023

Ah I didn't see the <title> 🙈 Would be good to investigate this in the docs repo then.

@bluwy bluwy added feat: styling Related to styles (scope) - P2: nice to have Not breaking anything but nice to have (priority) and removed needs repro Issue needs a reproduction labels Mar 14, 2023
@J-env
Copy link
Author

J-env commented Mar 15, 2023

Is the following optimization scheme feasible:

  1. css smaller than build.cssInlineLimit will be inlined
// astro.config.ts
export default defineConfig({
  build: {
    cssInlineLimit: 1024 * 4
  }
})

cssContent.fileSize <= build.cssInlineLimit output:

<!DOCTYPE html>
<html lang="en">
<head>
  <style>.test{color:red}</style>
</head>
<body>
  <div class="test">test</div>
</body>
</html>
  1. Lag some css at developer's option
---
import Dialog from '@/components/Dialog.astro'
// OtherDialog.astro
---

<Dialog class="other-dialog">
  <div class="other-dialog-box">content...</div>
</Dialog>

<style is:to="body" lang="scss">
  .other-dialog {
    .other-dialog-box {
      width: 600px;
      background: #fff;
      border-radius: 8px;
    }
  }
  
  // scss...
</style>

cssContent.fileSize <= build.cssInlineLimit output:

<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
  <div class="other-dialog"><div class="other-dialog-box">content...</div></div>
  <style>.other-dialog .other-dialog-box { width: 600px;background: #fff;border-radius: 8px}</style>
</body>
</html>

cssContent.fileSize > build.cssInlineLimit output:

<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
  <div class="other-dialog hidden"><div class="other-dialog-box">content...</div></div>
  <link href="./other-dialog.hash.css" rel="stylesheet">
</body>
</html>
  1. css shared by multiple pages should be merged into base.css or (chunk1.css/chunk2.css/...)

@Princesseuh
Copy link
Member

Closing since a solution has been implemented (currently in experimental https://docs.astro.build/en/reference/configuration-reference/#experimentalinlinestylesheets )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: styling Related to styles (scope)
Projects
None yet
Development

No branches or pull requests

4 participants