Search code examples
javascriptangulariisangular-cliangular-cli-v6

Javascript should be application/javascript or text/javascript in Angular CLI bundle?


Angular CLI will inject

<script type="text/javascript" src="main.d671592f0d56c3577479.js"></script>

to index.html. However, when investigating why IIS won't compress javascript files even though the compression setting is on, I realized that by default MIME type for javascript is application/javascript. This is why the compression did not happen. So my workaround is to modify the MIME type definition is the IIS site. However, I suppose the real solution is that Angular CLI inject

<script type="application/javascript" src="main.d671592f0d56c3577479.js"></script>

to index.html.

Do you agree? If so, does Angular CLI support this? or you have some way?


Solution

  • There is a closed / rejected issue in @angular/cli that blames Webpack. Alas, I'm reasonably certain Webpack actually would enable you to manually set MIME types, but the respective settings are not forwarded by the cli.

    Changing the type after the fact in a post-build script or during serving in IIS seems a reasonable workaround.