简体   繁体   English

如何在 asp.net mvc 4.5 中预加载捆绑包

[英]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.我还想预加载我们的 Bundle,但我不知道部署后将呈现的确切名称和查询字符串版本。 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':您可以使用“ResolveBundleUrl”:

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

Or you can use the 'Scripts.RenderFormat':或者您可以使用“Scripts.RenderFormat”:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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