Base solution for your next web application
Open Closed

Development/Production environemt name tags in code #5340


User avatar
0
panic created

Hello, I am using the Asp.Net Core+JQuery, full .net. Should we manually add code to include (or not) minified versions of js/css files in our views? Additionally, I noticed that for modal views (like _CreateOrEditModal.cshtml) you already generate minified versions of their js files (_CreateOrEditModal.min.js). Below code is to define a js variable for the modal. Can I select js file for scriptUrl according to value of env.name variable ASPNETCORE_ENVIRONMENT?

var _createOrEditModal = new app.ModalManager({
            viewUrl: abp.appPath + 'App/Languages/CreateOrEditModal',
            scriptUrl: abp.appPath + 'view-resources/Areas/App/Views/Languages/_CreateOrEditModal.js',  //Can I select minified js according to env.name variable ASPNETCORE_ENVIRONMENT if set to Development or Production
            modalClass: 'CreateOrEditLanguageModal'
        });

Many thanks,

P.

* How to handle loading minified versions if on Dev or Prod environments.

@section Scripts
    {
    <environment names="Development">
        <script src="~/view-resources/Areas/App/Views/Banking/Create.js" asp-append-version="true"></script>
    </environment>
    <environment names="Production;Staging">
        <script src="~/view-resources/Areas/App/Views/Banking/Create.min.js" asp-append-version="true"></script>
    </environment>
}
@section Styles
    {
    <environment names="Development">
        <link rel="stylesheet" href="~/view-resources/Areas/App/Views/Banking/Create.css" asp-append-version="true" />
    </environment>
    <environment names="Production;Staging">
        <link rel="stylesheet" href="~/view-resources/Areas/App/Views/Banking/Create.min.css" asp-append-version="true" />
    </environment>
}

4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @Panic,

    If you use

    <script abp-src .... />
    

    instead of

    <script src .... />
    

    it will do that as well. This is also valid for styles. You can use

    <link abp-href ... />
    

    instead of

    <link href ... />
    
  • User Avatar
    0
    panic created

    Hello, Do you mean that instead of this:

    <script src="~/view-resources/Areas/App/Views/Banking/Create.js" asp-append-version="true"></script>
    

    If I use this:

    <script abp-src ="~/view-resources/Areas/App/Views/Banking/Create.js" asp-append-version="true">
    

    It will automatically load Create.min.js if exists, otherwise it will just load Create.js ?

    Is there any documentation regarding "<script abp-src" and "<link abp-href ... />"? Many thanks,

    Panayiotis.

  • User Avatar
    0
    panic created

    .. I found some explanation in this link [https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3034])

  • User Avatar
    0
    ismcagdas created
    Support Team

    Yes, it works like that :)