How to preload bundle in mvc 4.5

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


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">


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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")

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x