Skip to content

Commit aedcab5

Browse files
matthewpsarah11918
andauthored
Document inline stylesheets (#3355)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
1 parent 669b6d5 commit aedcab5

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/content/docs/en/guides/styling.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,30 @@ You can apply global styles to your Markdown content by adding [`<style>` tags](
514514

515515
If you are using Tailwind, the [typography plugin](https://tailwindcss.com/docs/typography-plugin) can be useful for styling Markdown.
516516

517+
## Production
518+
519+
### Bundle control
520+
521+
When Astro builds your site for production deployment it combines your CSS into chunks. Each page on your site is its own chunk, and additionally, CSS that is shared between multiple pages is further split off into their own chunks for reuse.
522+
523+
In each of your HTML files there will be `<link rel="stylesheet">` tags added, one for each of the chunks that the pages needs.
524+
525+
Sites with a large number of pages and many different shared styles can lead to many stylesheet requests and affect site performance. You can configure the `inlineStylesheets` option to reduce the number of these requests by putting (minimized) stylesheets into a `<style>` tag rather than request them externally.
526+
527+
```js
528+
import { defineConfig } from 'astro/config';
529+
530+
export default defineConfig({
531+
build: {
532+
inlineStylesheets: 'auto'
533+
}
534+
});
535+
```
536+
537+
The `'auto'` option will inline only the stylesheets that are below the `vite.build.assetsInlineLimit` threshold, reducing the number of requests for smaller sheets. Larger stylesheets, such as global ones used by all pages, will still be fetched externally and cached. This option provides a balance between the number of stylesheets loaded and the styles that can be cached between pages.
538+
539+
You can also set this option to `'always'` which will inline all stylesheets.
540+
517541
## Advanced
518542

519543
:::caution

0 commit comments

Comments
 (0)