Concatenate and minify JavaScript on the fly OR at build time - ASP.NET MVC

后端 未结 8 2366
日久生厌
日久生厌 2020-11-29 15:38

As an extension to this question here Linking JavaScript Libraries in User Controls I was after some examples of how people are concatenating and minifying JavaScript on the

相关标签:
8条回答
  • 2020-11-29 16:08

    Here's what I've used for concatenating, compressing and caching CSS and JS files: http://gist.github.com/130913

    It just requires Yahoo.Yui.Compressor.dll in the bin directory. It doesn't compress at compile time, but the files are cached with a file dependency, so they are only loaded once, until they're changed.

    Then I just add this code in the <head>:

    <link rel="stylesheet" type="text/css" href="/YuiCompressor.ashx?css=reset,style,etc" />
    

    and this just before the </body>:

    <script type="text/javascript" src="/YuiCompressor.ashx?js=main,other,etc"></script>
    

    It's designed to work with multiple files all in the same path but could easily be upgraded to support different paths.

    0 讨论(0)
  • 2020-11-29 16:19

    In the appendix of Professional ASP.NET 3.5 Scott Hanselman talks about Packer for .NET. This will integrate with MSBuild and pack javascript files for production deployments etc.

    0 讨论(0)
提交回复
热议问题