开发者

Should I load entire jQuery UI JS/CSS or only the parts that I need on a certain page?

I know what many of you will say. This is a stupid question, or maybe this is not the right forum, or depend on the application, etc.

I am just wondering if I have a custom theme, that I might change in future is it a good idea to separate the jQuery UI, I mean the JS classes and CSS in smaller chunks (files like droppable,etc.) and include only the one that I need on certain page or keep them together and load the entire UI on every page. Both have positives and negatives. I am just not sure which is better.

What is your opinion. Any different approach po开发者_如何学Gossible?


My personal opinion is, if you want to keep up to date in the future, it would be far easier to keep the jQuery UI files complete, otherwise in the future to update you will have to spend time splitting the new versions.

If there are features you know you don't and won't use, you could remove those during the download by simply selecting the features you will use.

I also think the load time would be insignificant, once the browser has loaded the script, it is likely to cache a copy of it so a user isn't reloading the script with every page. Plus the server only has to serve two files, instead of the overheads to potentially serve multiple files.

It will also help for future development of your site scripting in the sense if you want to add an extra feature to your script, you won't need to remember if you have loaded the required js/css part files.


i think it will be better if you load entire jQuery ui js/css, because if in future if you want to do some thing new in jquery then again you have to look at those parts which would be required to do this stuff, and you have to make extra efforts to put those chunk of code in your js file so i think loading the entire jquery will be better approach!!


Load the entire jQuery UI JS and CSS, but make sure that the JS only contains the modules you need.

ie. if you don't use Draggable or Droppable anywhere on your site, don't include it!

Even if you don't every module on every page, the performance benefits you will get from caching the entire JS on the first page hit (as opposed to multiple different smaller files on multiple pages) and fewer HTTP requests (one large file vs many small files) will make up for it.


Not a stupid question, is the right forum, BUT it does depend on the application!

I think the best solution in general to ensure is to minimize the requests and size of files that the client downloads, but at the same time ensure that you the dev. can replace and change parts of the code easily and be sure that your client gets those updates.

To that end, really what you need is a combination of deployment process and server-side process that automatically combines the scripts/css , but also allows you to bust the client cache, when those assets are changed. You should also serve as much as you can from a CDN. Also you need to make sure your webserver has Expires headers set on those assets.

Depending on the sever side framework some of these might be handled for you.

FOr example here is how github do (did?) it with rails https://github.com/blog/551-optimizing-asset-bundling-and-serving-with-rails

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜