You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ng generate serviceWorker --project my-app-ngsw
ng build --prod
Desired functionality
All JS files generated for the service workers are unminified (worker-basic.min, ngsw-worker.js and safety-worker.js). I'd suggest that these are minified.
Reacted by Isabella Weber, Elchin Asgarli, ✅ Daniel Danielecki, Zygimantas, Volker Andres, Mohamed Boughaba, David Journot, Michael Prentice, Sebastian Davids and Geoffrey Testelin
in the event of issues in production, we get much better stack traces from an unminified SW.
ngsw-worker.js is at 136KB which quite large.
As minifying JS seems rather easy... Could you please explain which kind of stack loss one would expect?
I am asking this because I am considering to run a post build task to minify the file til we get a fix
That said, at some point it will make sense to minify the SW bundles.
@alxhub we don't have to mangle it? For a quick fix can't we trim the spaces and strip the comments etc? This would make it considerably smaller and won't lose out with debugging.
i also think the ngsw.js should be mini- and uglified (i use the terser cli after ng build as a workaround, but out of the box would be nice). i stumbled upon it while aggressivly tuning first load perfomance on a page i work on. There are tons of non-license comments aswell. Doesnt make sense to deliver those in prodmode.
My tests have shown that you can achieve a reduction of about 60-70% (startetd with around 140k ended in around 50k - mini- & uglify, kept only licensing relevant Comments).
As the SW has to be delivered anyway, a minification would heavily improve the experience on low end devices and regions with slow connections. I'm thinking about emerging markets like India, Africa, etc.
Especially when connecting via HTTP/1.1 its a pain as it will occupy one of the 6 parallel connections without any benefit for the time to first interaction/paint.
i know i'm bit flipping here, but every 50ms we get for free is a piece of experience our users get for free aswell.
kind of offtopic: ngsw.json isnt minified aswell. minifying saves another bunch of kb - but i cant remember the numbers, i'd have to look them up from home after work.
Activity
filipesilva commentedon Jul 23, 2018
@alxhub I think you had an opinion about this topic, can you chime in?
alxhub commentedon Aug 10, 2018
Yes, I left the SW files unminified because
the SW is aggressively cached by the browser and downloaded out-of-band with page rendering, so file size is not a major concern.
in the event of issues in production, we get much better stack traces from an unminified SW.
That said, at some point it will make sense to minify the SW bundles.
jraadt commentedon Apr 8, 2019
I feel that angular/angular#21191 should be fixed before these files are minified.
mboughaba commentedon Jul 14, 2019
@alxhub
ngsw-worker.jsis at136KBwhich quite large.As minifying JS seems rather easy... Could you please explain which kind of stack loss one would expect?
I am asking this because I am considering to run a post build task to minify the file til we get a fix
Would it be possible to provide a target date?
re-thc commentedon Oct 4, 2019
@alxhub we don't have to mangle it? For a quick fix can't we trim the spaces and strip the comments etc? This would make it considerably smaller and won't lose out with debugging.
kmturley commentedon Nov 23, 2019
I managed to minify the workers using:
npm install webpack-cli --save-devwebpack.workers.js
package.json
Then running:
npm run build && npm run build:workersnlappe commentedon Jan 31, 2020
i also think the ngsw.js should be mini- and uglified (i use the terser cli after ng build as a workaround, but out of the box would be nice). i stumbled upon it while aggressivly tuning first load perfomance on a page i work on. There are tons of non-license comments aswell. Doesnt make sense to deliver those in prodmode.
My tests have shown that you can achieve a reduction of about 60-70% (startetd with around 140k ended in around 50k - mini- & uglify, kept only licensing relevant Comments).
As the SW has to be delivered anyway, a minification would heavily improve the experience on low end devices and regions with slow connections. I'm thinking about emerging markets like India, Africa, etc.
Especially when connecting via HTTP/1.1 its a pain as it will occupy one of the 6 parallel connections without any benefit for the time to first interaction/paint.
i know i'm bit flipping here, but every 50ms we get for free is a piece of experience our users get for free aswell.
kind of offtopic: ngsw.json isnt minified aswell. minifying saves another bunch of kb - but i cant remember the numbers, i'd have to look them up from home after work.
gkalpak commentedon May 17, 2020
BTW, minifying the SW scripts is tracked in angular/angular#27490.
alan-agius4 commentedon Aug 21, 2020
Closing in favour of angular/angular#27490.
angular-automatic-lock-bot commentedon Sep 21, 2020
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.