2

I saw how it can be done in MVC, but for a specific project I'm using Web-Forms.

I have

<asp:PlaceHolder ID="PlaceHolder1" runat="server">
    <%: System.Web.Optimization.Scripts.Render("~/file.js") %>
</asp:PlaceHolder>

which generates the html:

<script src="/file.js?v=5jui8vHEj5_iAkaGiAccPPb2LcsdK1jQ1"></script>

I wish to add the sync attribute to the above tag.

I'd appreciate some guidance. Thanks.

Andy G
  • 19,232
  • 5
  • 47
  • 69
Hans Webb
  • 127
  • 2
  • 9

2 Answers2

5

You can use RenderFormat to achieve this:

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

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

afzalulh
  • 7,925
  • 2
  • 26
  • 37
  • Thanks. I couldnt find RenderFormat until I realized it's only available in v. 1.1.0 of Web.Optimization – Hans Webb Sep 03 '13 at 20:35
0

This method would should the magic:

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

I extract from:

Bundling and Minification

Adhemar
  • 387
  • 5
  • 12