ASP.NET Core MVC Controls | ComponentOne
Configuring your MVC Application / Deferred Scripts
In This Topic
    Deferred Scripts
    In This Topic

    The HTML Script Element ( <script> ) is used to embed or reference an executable script within an HTML or XHTML document. Scripts without async or defer attributes, as well as inline scripts, are fetched and executed immediately, before the browser continues to parse the page. According to the industry standards, it is recommended that you put all the scripts at the bottom of your HTML page and style sheets at the top. When C1 scripts are registered at the bottom, the startup scripts of controls also need be registered at the bottom.

    You should follow the following process to add deferred scripts in the _Layout.cshtml page.

    1. Register styles in the head tag.
    2. Register script files before the end of <body> tag.
    3. Register startup scripts before the end of <body> tag.

    The scripts for a MVC control include two parts: necessary scripts files and startup scripts. We provides different methods to enable deferred script for MVC 3/4/5 and ASP.NET Core application. There are 2 scopes through which deferred scripts can be applied: application level and page level. As the name implies, application level means all the ComponentOne controls in this application will use deferred scripts, while page level means only ComponentOne controls defined in the page use deferred script.

    Web.config
    Copy Code
    <c1-deferred-scripts />
    

    Deferred Scripts - Switcher

    When a user turn on the switcher, the startup script of the control is suspended.

    At app level, the current razor page renders at first, and later the _layout page is rendered. In this case, the user needs to move deferred scripts app level switcher to web.config file or startup.cs file.

    At switcher level, once you set EnableDeferredScripts to true in the Action method of the controller, all the startup scripts for the C1 MVC controls in the page are suspended.

    Web.config
    Copy Code
    app.C1().EnableDeferredScripts();