Search code examples
javascriptasp.netasp.net-core-mvcminifyasp.net-core-2.0

asp.net core 2.0 load unminified script for specific view


So I want to load a specific javascript file for one particular view. At the moment I implemented it like this (production code):

<script src=@Url.Content("js/someLibrary.min.js")></script>

But for my development environment I want to load the unminified version of this file. However when I leave this code as it is it will still pull the min.js file from the server.

Is there any way in which I can load the unminified version depending on my current environment for a specific view, without loading the file in every view (through _Layout.cshtml)?


Solution

  • Assuming the unminified file is called js/someLibrary.js this should do the trick:

    <script src=@Url.Content("js/someLibrary.js")></script>
    

    EDIT:

    To be able to differentiate what to use when in dev mode and when in prod mode you can add a key to the appfile config and check its value.

    <add key="DevMode" value="true" />
    

    for your dev and

    <add key="DevMode" value="false" />
    

    for your prod. And then you can use

    ConfigurationManager.AppSettings("DevMode")
    

    to get its value.