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

Optimization of inline scripts behaves differently with default settings vs explicitly defined minification #20207

Closed
kmaraz opened this issue Mar 5, 2021 · 5 comments · Fixed by #20213

Comments

@kmaraz
Copy link

kmaraz commented Mar 5, 2021

🐞 bug report

Description

In the documentation for Optimization configuration https://angular.io/guide/workspace-config#optimization-configuration it is stated that:

option: scripts - Enables optimization of the scripts output.
and the default value is TRUE

So based on default values mentioned in the documentation I thought that

"optimization": { 
  "scripts": true,
  "styles": {
    "minify": true,
    "inlineCritical": false
  },
  "fonts": true
}

is the same as:

"optimization": true

But the two behaves differently. The explicit configuration of optimization.scripts = true option turns on aggresive minification of inlined <script>s in the index.html which is not enabled when only optimization = true is set.

Did I get it wrong and it should behave differently?

🌍 Your Environment

Angular Version:


  "@angular-builders/custom-webpack": "^11.1.0",
    "@angular-devkit/build-angular": "^0.1102.2",
    "@angular-eslint/eslint-plugin": "^1.2.0",
    "@angular-eslint/eslint-plugin-template": "^1.2.0",
    "@angular-eslint/template-parser": "^1.2.0",
    "@angular/animations": "^11.2.3",
    "@angular/cdk": "^11.2.2",
    "@angular/cli": "^11.2.2",
    "@angular/common": "^11.2.3",
    "@angular/compiler": "^11.2.3",
    "@angular/compiler-cli": "^11.2.3",
    "@angular/core": "^11.2.3",
    "@angular/elements": "^11.2.3",
    "@angular/forms": "^11.2.3",
    "@angular/language-service": "^11.2.3",
    "@angular/material": "^11.2.2",
    "@angular/material-moment-adapter": "^11.2.2",
    "@angular/platform-browser": "^11.2.3",
    "@angular/platform-browser-dynamic": "^11.2.3",
    "@angular/router": "^11.2.3",
@gkalpak gkalpak transferred this issue from angular/angular Mar 5, 2021
@alan-agius4
Copy link
Collaborator

Hi @kmaraz,

Inline scripts should never be optimized. I noticed that you are using @angular-builders/custom-webpack, can this be caused by this 3rd party builder?

Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

@alan-agius4 alan-agius4 added the needs: repro steps We cannot reproduce the issue with the information given label Mar 5, 2021
@kmaraz
Copy link
Author

kmaraz commented Mar 5, 2021

I'll do it, thanks!

@kmaraz
Copy link
Author

kmaraz commented Mar 5, 2021

Hi @alan-agius4, here it is: https://github.com/kmaraz/angular-optimization-bug

When I was testing it I have found the bug:

When the setting is:

"optimization": true,

Everything is correct.

When the setting is:

"optimization": {
  "scripts": true,
  "styles": {
    "minify": true,
    "inlineCritical": false
  },
  "fonts": true
},

Everything is correct.

But when I set:

"optimization": {
  "scripts": true,
  "styles": {
    "minify": true,
    "inlineCritical": true <<<<<<< THIS
  },
  "fonts": true
},

Then the code inside <script> tag is processed and broken.

Script in index.html before:

 <script>
    (function(t,e){var n=""+l(t)+!!e;this.xhrGuids&&!this.xhrGuids[n]&&(this.xhrGuids[n]=!0,this.totalCbs+=1)})
  </script>

Script in index.html after (as seen in dist directory in the repo):

<script>
    (function(t,e){var n+l(t)+!!e;this.xhrGuids&&!this.xhrGuids[n]&&(this.xhrGuids[n]=!0,this.totalCbs+=1)})
  </script>

Is there anything else I can do?

@alan-agius4
Copy link
Collaborator

Hi @kmaraz, thanks for the reproduction. I tracked down the bug and have a PR in flight to address this #20213.

filipesilva pushed a commit that referenced this issue Mar 8, 2021
filipesilva pushed a commit that referenced this issue Mar 8, 2021
…tributes empty values

Closes #20207

(cherry picked from commit 84f3977)
@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 Apr 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants