How to publish only bundled/minified scripts

拟墨画扇 提交于 2019-12-06 03:53:27

问题


I have a MVC4 project that is deployed to Azure. The bundling and minification works absolutely fine.

All the script files are in a folder /js which are bundled to /scripts/js

When I publish to Azure using msdeploy, I would like only the bundled/minified script files to be deployed. I don't want anyone getting access to my un-minified scripts by guessing the url.

I understand MVC bundling happens at runtime hence it would require the unbundled files to create the bundles on the fly. This probably needs to be automated with something like grunt maybe?

Want to know what deploy strategy people use in such cases when you dont want to publish unbundled js.


回答1:


using Web Deploy you can set the skip parameter:

http://technet.microsoft.com/en-us/library/dd569089%28WS.10%29.aspx

here's a sample:

http://blog.richardszalay.com/2012/12/18/demystifying-msdeploy-skip-rules/




回答2:


They get your scripts on pageload, so I don't see why them seeing the unminified version should be a big concern, unless maybe you have crazy or offensive comments in your unminified version. Users could use a javascript formatter, like discussed in this SO post to get the minified files back into a readable format.

Though, for your concerns, you could simply drop a web.config file in the deployed /js folder to keep anything from being served up. In my testing, this did not impact minification. Although if you put it in your local folder, you'll have errors bundling in debug mode (since debug mode serves up the individual files and this web.config keeps anything from being served):

<?xml version="1.0"?>
<configuration>
    <system.web>
        <authorization>
            <deny users="*" />
        </authorization>
    </system.web>
</configuration>

Another concern is, depending on how paranoid you are at someone seeing an unminified script, you may have to write your own BundleBuilder class for reasons detailed in How to prevent User-Agent: Eureka/1 to return source code, which reveals how users can see unminified bundles with comments by changing their user-agent.



来源:https://stackoverflow.com/questions/21745707/how-to-publish-only-bundled-minified-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!