简体   繁体   中英

How to use defer or webworker api with SquishIt MVC framework?

I am using SquishIt MVC framework for bundling and minification of the js and css components present in the application. The code is as mentioned below:

public static class HTMLHelperExtensions
{
  public static MvcHtmlString PackageLibs(this HtmlHelper htmlHelper)
  {
    var client = Bundle.JavaScript() 
     .Add("~/scripts/jquery-1.7.1.min.js")
     .Add("~/scripts/jquery-ui-1.8.17.min.js")
     .Render("~/scripts/combined.js");

    return new MvcHtmlString(client);
  }
}

I am invoking the method : HTMLHelperExtensions from the layout page.

<%= HTMLHelperExtensions() %>

I want to use the defer attribute to boost the JavaScript performance of a web page.

Can anyone help me to know the usage of the defer attribute? I would like to know also is the usage of webworker useful here.

Thanks & Regards, Santosh Kumar Patro

To render with deferred load, change your bundle setup like so:

 var client = Bundle.JavaScript() 
     .Add("~/scripts/jquery-1.7.1.min.js")
     .Add("~/scripts/jquery-ui-1.8.17.min.js")
     .WithDeferredLoad()
     .Render("~/scripts/combined.js");

Web workers seem like overkill for something as trivial as script loading IMO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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