简体   繁体   中英

How to preload bundle in asp.net mvc 4.5

I am using following code, to add bundle to my layout.

@Scripts.Render("~/bundles/ngapp")

I would also like to preload our Bundle, but I do not know exact name and query string version which will be rendered after deploy. How can I change this piece of code to be something like this:

  <link rel="preload" href="@Scripts.BundleName("~/bundles/ngapp")" as="script">
@Scripts.Render("~/bundles/ngapp")

I think there are multiple ways to do this.

You can make use of the 'ResolveBundleUrl':

<link rel="preload" href="@(BundleTable.Bundles.ResolveBundleUrl("~/bundles/scripts"))" as="script">

Or you can use the 'Scripts.RenderFormat':

@Scripts.RenderFormat("<link rel='preload' href='{0}' as='script'>", "~/bundles/scripts")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM