Skip to content Skip to sidebar Skip to footer

Add An 'async' Attribute To A Js Include Tag In Asp.net Web Forms

I saw how it can be done in MVC, but for a specific project I'm using Web-Forms. I have <%: System.Web.Optimization

Solution 1:

You can use RenderFormat to achieve this:

 <%: System.Web.Optimization.Scripts.RenderFormat ("<scriptsrc='{0}'async ></script>", "~/file.js") %>

Renders as: <script src="/file.js" async=""></script>

Solution 2:

This method would should the magic:

<scriptsrc='<%: System.Web.Optimization.Scripts.Render("~/file.js") %>'async></script>

I extract from:

Bundling and Minification

Post a Comment for "Add An 'async' Attribute To A Js Include Tag In Asp.net Web Forms"