Yui files are too heavy and affect site's performance
I ve developed an asp.net web application with YUI as the javasc开发者_如何转开发ript library... My site was very slow that it took three minutes to view my page on my first visit....
- When inspected through firebug, My yui file was too heavy with size 278kb...
- what can be done to improve performance?
278k is less than many images that appear on websites, and YUI is only as heavy as the component stack that you have requested. The common core package yahoo-dom-event.js is 37k (12k gzipped), so you are requesting at least a few other modules. That said, even across a slow connection, 278k should not cause a 3 minute delay. I suspect there is something else causing the performance issue.
There are many tactics for improving page performance. As MontyBongo suggests, use the Yahoo! CDN. If you are hosting the files yourself, make sure you have gzip enabled on your server. One benefit to using the CDN is the ability to use the Combo handler, which bundles all modules into a single script file. If self hosted, you should look into creating manual rollups of the files you are using to emulate this. Also, look into the YUI Loader to bring in module files asynchronously. http://developer.yahoo.com/yui/yuiloader/
Otherwise, look at http://developer.yahoo.com/performance/ and ask on yuilibrary.com/forum for advice. Please note that you should always supply some code for reference when asking for advice to improve it. Paste code snippets inline, link to larger snippets on http://pastie.org or http://gist.github.com, link to the page in question, or (best of all) link to a reduced page that illustrates in isolation the issue you want to address.
Try compressing the javascript with gzip, if possible use the Yahoo or Google CDN to deliver the files: http://developer.yahoo.com/yui/articles/hosting/
Also try install YSlow, it can give you some good feedback on whats causing your page to load slowly, and provides some tips on optimizing the javascript delivery http://developer.yahoo.com/yslow/
I agree that YUI is a bit too heavy for many sites.
In case it helps, you might want to have a look at my book for some ideas on how to make things run faster: Ultra-Fast ASP.NET: Build Ultra-Fast and Ultra-Scalable web sites using ASP.NET and SQL Server.
精彩评论