Public Conditional Razor Views with minified JS and CSS

折月煮酒 提交于 2019-12-07 11:32:10

问题


I am using ASP.NET MVC 5 to develop my website. I'm using Grunt to minify my CSS and JS. Everything works fine, but I need to change the route source of my files if I'm making a publish (release mode) or I'm debugging (I need to read my CSS and JS clearly).

Something like this:

[Debug Mode]

<script src="scripts/myscript.js"></script>

[Relase Mode or Public Mode]

<script src="dist/myscript.min.js"></script>

I have read this post on StackOverflow(Razor view engine, how to enter preprocessor(#if debug)) and I don't like the proposed solution because I think (not sure) that the loaded Razon View is going to check always in Production Server if it's in release or debug mode and I think that it's not necessary.

Can someone confirm if I am right? Will I will need make the changes manually? Any other solution?

Thanks!! Regards!!


回答1:


One way you could accomplish this is to just check for debug mode in the http context.

@if (HttpContext.Current.IsDebuggingEnabled)
{
    <script src="scripts/myscript.js"></script>
}
else
{
    <script src="dist/myscript.min.js"></script>
}


来源:https://stackoverflow.com/questions/28400135/public-conditional-razor-views-with-minified-js-and-css

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