Scripts.Render() if not exists

I want the following call to render only if such call wasn't already declared in a parent view.


What's the best way to do so?



Here is one way:

    if (!window.jQuery) {
        document.write('<script src="@BundleTable.Bundles.ResolveBundleUrl("~/Scripts/jQuery")">\x3C/script>');

This is essentially the same logic used when one includes jQuery from a CDN, and then has a local reference fallback if the CDN delivery failed.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.