-1

Hi can someone explain me what happens if I run ng build --prod twice without changing anything. Is there some optimation behind or gets every file transpiled/recompiled no matter if there is a file change or not.

Can someone explain the generated file hashes? what is the puropose and does ng use them somehow?

Cowas
  • 328
  • 2
  • 12

2 Answers2

1

if you look through the generated html you will find your scripts requested. <script src="bundle.hashhashhash.js"></script> this script can be easilly cached wich improves your app start time. if you compile your app with changed src you will get another hash wich signals the browser to use new script instead of the cached one

Andrei
  • 10,117
  • 13
  • 21
0

Purpose of the hash in your file names is a signal for the browsers to download your files again if they are cached.

Let's put it in this way.

Say that the ng build --prod hashes remain the same every time that you run it. So you have something like main-1234.js

Now you deploy the app and someone visits your page and the browser will download and cache your files.

After some time, you deploy a new version and you still generated the main-1234.js file. Now the user that visited your site before won't get the new version of your files since the browser already cached it. It will take sometime for them to see the new files if the cache expired and this is usually not the behavior that you want.

Angular does not use or care about the hash value when you're building for production. It actually erases your files under dist when you run the ng build --prod. Try it :)

brijmcq
  • 3,354
  • 2
  • 17
  • 34