locked
How to download minified / bundled js file by javascript on page load? RRS feed

  • Question

  • User-454825017 posted

    This way i have bundled my js files

    bundles.Add(new ScriptBundle("~/bundles/bs-jq-bundle").Include(
                          "~/Scripts/bootstrap.js",
                          "~/Scripts/jquery-3.3.1.js"));
    

    I do not want to use @Scripts.Render("~/bundles/bootstrap") to download file at client side. rather i want to download all bootstrap js file when page load means i want to do defer loading by javascript

    I know below way i can download that bundle by javascript but for that i have to know the exact token. from where to get token value ?

    <script type="text/javascript">
    function downloadJSAtOnload() {
                var element = document.createElement("script");
                element.src = "/Scripts/JQueryBundle?v=vFo0kKa-_2_wGzi6Q0u-IemkcVvXrEdKz7OrQ9g-y_c1";
                document.body.appendChild(element);
            }
    
    
    </script>
    
    
    // Check for browser support of event handling capability
    if (window.addEventListener)
    window.addEventListener("load", downloadJSAtOnload, false);
    else if (window.attachEvent)
    window.attachEvent("onload", downloadJSAtOnload);
    else
    window.onload = downloadJSAtOnload;

    i also know when any file code changes then token value also changed. so if i use static token then how that works always.

    see the javascript code which download bundled js file on page load and where a static or fixed token used to download bundled js file at client side. so tell me how does it work when any js file code changed in that bundle ?

    please guide me. thanks

    Thursday, October 15, 2020 6:21 PM

Answers