Setup IIS10 to serve pre-compressed files RRS feed

  • Question

  • User1860031277 posted

    Hi all,

    my angular2 projects build pre-compressed gzip files for my web-app but my IIS only serves the normal ".js" files instead of the compressed ".gzip" files. My browser is willing to accept gzip.

    What is the correct setting for IIS to allow gzip responses with already compressed content?

    I already searched google/SO/SU but only found solutions for not "pre-compressed" content.

    Kind regards and thanks for any help.

    Tuesday, February 20, 2018 8:24 AM


All replies

  • User690216013 posted

    As this is an IIS forum, my advice is to disable pre-compression in your Angular project. IIS can compress the files on the fly and cache them, which won't waste too much resources.

    There might be developers who claimed to solve the issue, https://stackoverflow.com/questions/40884212/serve-bundle-js-gz-file-on-iis but you should chase them on Stack Overflow, not here.

    ASP.NET Core might have better pre-compression support, as there is a thread discussing what to do, https://github.com/aspnet/Home/issues/2458 But I don't think much can be done for IIS and ASP.NET 4.x (can be done, but not quite obvious).

    Tuesday, February 20, 2018 5:04 PM
  • User1860031277 posted

    Thanks for your answer Lex,

    unfortunately, this is not an option. Angular is AOT compiled and tree shook - furthermore with <g class="gr_ gr_23 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="23" data-gr-id="23">brotli</g> uglified and minified. Things that IIS can't achieve. I already tested this but there are dramatic size differences (~50%). My App is a PWA and therefore size and speed are key.

    Also, I serve my Client and API from a different location (they are independent) so there is no way I could handle this inside my API. Also, I use ASP.NET Core 2.0.

    While this is a common problem for modern web-technologies it's sad to see that IIS is not able to handle such "basic requirements". It's a piece of cake for apache or <g class="gr_ gr_17 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="17" data-gr-id="17">nginx</g> but unfortunately, the technology stack is set.

    I'll look at your link and hope this will help.

    Thanks for your reply.

    Tuesday, February 20, 2018 8:23 PM
  • User-460007017 posted

    Hi  Heurazio,

    IIS may not compress the pre-compressed file while IIS have its own compression module. However, the following links provide some steps to achieve this.



    Best Regards,

    Yuk Ding

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Wednesday, February 21, 2018 2:10 AM
  • User-1202101404 posted

    While I know nothing of precompressed js files, per se, it would seem your answer would be in needing to define an entry in the IIS "mime types" page, either at the server or site level, . I see a ".gz" one in my IIS 10 by default. See what happens if you add a .gzip one (you can see the .gz one as a model for the mime type value, which shows "application/x-gzip"). 

    Of course, defining it at the server level in IIS is best if you mean it to apply to all sites.

    Just beware: if you do it at the server level, and your testing fails, do check the site level "mime types" feature. Someone could have a config element for the site (in the web.config or applicationhost.config) that clears all server-level mime types and names specific ones. In that case, define it in the site-level mimetypes feature.

    Thursday, February 22, 2018 1:54 AM
  • User1860031277 posted

    Hi Yuk, your first link was helpful and I got the gzip files working with a URL-rewrite. I now have an additional problem which is related to angular so I will accept your answer. Thanks again.

    Thursday, February 22, 2018 3:27 AM