1

I was reading about asynchronous CSS loading here and I was wondering if it is possible to use that kind of behaviour in MVC5 bundles.

What I want to achieve is multiple bundled CSS files downloaded in a non-blocking way (meaning faster loading time of my page)

2 Answers 2

2

There's a method on the Styles helper where you can set your own tag format.

@Styles.RenderFormat("<link href=\"{0}\" rel=\"preload\" as=\"style\"/>",
                     "~/Path/To/My/Bundle")
Sign up to request clarification or add additional context in comments.

Comments

0

For full working solution I'm using the answer I marked as acceptance to this question, but I've added one more thing to it to make it work 100%

onload="this.rel='stylesheet'"

so working example is:

C# file:

public const string StyleRenderFormat = "<link href=\"{0}\" rel=\"preload\" as=\"style\" onload=\"this.rel='stylesheet'\"/>";

cshtml file:

@Styles.RenderFormat(BundleConfig.StyleRenderFormat, "~/myCssBundleName")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.