Skip to content

Add option to output styles inline #11395

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

Closed
filipbech opened this issue Jun 28, 2018 · 9 comments · Fixed by #19449
Closed

Add option to output styles inline #11395

filipbech opened this issue Jun 28, 2018 · 9 comments · Fixed by #19449
Assignees
Labels
area: @angular-devkit/build-angular devkit/build-angular:browser feature Issue that requests a new feature needs: investigation Requires some digging to determine if action is needed
Milestone

Comments

@filipbech
Copy link

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Area

- [x] devkit
- [ ] schematics

Desired functionality

It would be cool if there was a build-option that would take the processed/minified css and put it inline in a <style>-element in index.html instead of as a seperate file.
Useful when it doesn't change so often, and the styles are limited.

Rob asked me to make a Feature-request... https://twitter.com/robwormald/status/1012084975766626304

Mention any other details that might be useful

@christianliebel
Copy link
Contributor

Useful for critical/“above-the-fold” CSS. Maybe it’s also possible to process the contents of a style tag in src/index.html?

@slavoroi
Copy link

slavoroi commented Oct 28, 2019

What is the status with this ticket?
It will be amazing if we could have an option:

"styles": [
      "src/styles.scss"
  ],
"inline-styles": [
      "src/inline-styles.scss"
  ]

Or

"styles": [
      { "input": "src/inline-styles.scss", "inline": true }
  ]

And it will add the styles in the index.html inline in the head with
ng build ---prod.

@naveedahmed1
Copy link

I would also suggest adding inline and preload options in styles in angular.json file

"styles": [
      { "input": "src/critical-path-styles.scss", "inline": true },
      { "input": "src/lazy-styles.scss", "preload": true }
  ]

With above settings, Angular CLI should inline the contents of critical-path-styles.scss in head tag, and it should generate <link href="https://github.com/lazy-styles.96106fab.css" rel="preload" as="style" onload="this.rel='stylesheet'"> for lazy-styles.scss.

@dgp1130 dgp1130 added needs: investigation Requires some digging to determine if action is needed and removed needs: discussion On the agenda for team meeting to determine next steps labels Jun 5, 2020
@spock123
Copy link

spock123 commented Oct 25, 2020

Hi, is there any hope of this ever becoming a feature?
Running lighthouse tests just gives red lights all over because of this. It's a pretty common thing to inline resources and it would be a great cli feature.

I would add that inlining the main bundle would also be a great feature.

Thanks again

@alan-agius4
Copy link
Collaborator

Hi,

We did an RFC for this see: #18730.

In the prerelease version of Angular CLI v11 inlining of fonts is already available, other parts of the RFC are scheduled to be available in 11.1.

@alan-agius4 alan-agius4 self-assigned this Oct 25, 2020
@spock123
Copy link

spock123 commented Oct 25, 2020

Hi,

We did an RFC for this see: #18730.

In the prerelease version of Angular CLI v11 inlining of fonts is already available, other parts of the RFC are scheduled to be available in 11.1.

Yeah I actually heard @mgechev mention it on the latest Angular podcast - I'm so happy - this is YUUGE guys!
Thank you so much

clydin pushed a commit that referenced this issue Dec 4, 2020
…optimizations

This is another feature that we mentioned in the Eliminate Render Blocking Requests RFC (#18730)

Inlining of critical CSS is turned off by default. To opt-in this feature set `inlineCritical` to `true`.

Example:
```json
"configurations": {
  "production": {
    "fileReplacements": [
      {
        "replace": "src/environments/environment.ts",
        "with": "src/environments/environment.prod.ts"
      }
    ],
    "optimization": {
      "styles": {
        "minify": true,
        "inlineCritical": true,
       }
    },
```

To learn more about critical CSS see;
https://web.dev/defer-non-critical-css
https://web.dev/extract-critical-css/

In a future version of the Angular CLI `inlineCritical` will be enabled by default.

Closes: #17966
Closes: #11395
Closes: #19445
@naveedahmed1
Copy link

Amazing work @alan-agius4 @clydin 👍

@spock123
Copy link

spock123 commented Dec 5, 2020

I'm gonna pour myself a gin/tonic and celebrate this. Thank you @alan-agius4 !

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular-devkit/build-angular devkit/build-angular:browser feature Issue that requests a new feature needs: investigation Requires some digging to determine if action is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants