Removing unused jQuery Mobile elements?

爷,独闯天下 提交于 2019-12-19 09:26:23

问题


I'm using jQuery Mobile beta. It's great fun to work with, but it's still very slow on a 3G connection.

It requires the following files:

http://code.jquery.com/jquery-1.6.1.min.js (89KB)
http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js (65KB)
http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css (41KB)

These are all above the 25KB iPhone cache limit, and even with a cache-manifest, mean that the site is pretty slow to render first time around.

Not unusably slow, but enough to be unpleasant (and yes, I know "slow" is subjective, but so is everything in UI development).

Has anyone figured out a way to cut down the size of these files - either the unused bits of jQuery, or a way to remove parts of the CSS file, depending on which elements are actually used?

Thanks a lot.


回答1:


there's no way to automate this process. If you want to go and remove what's not being used you have to do it yourself. But your gain will be minimal. You won't reach 25kb in any of them.

Use html5 cache manifest to store the files locally and as you've said only the first load will be slower. No way around it.




回答2:


I know this is an old question, but here goes anyway: You can use the jquerymobile "download-builder" to create a custom build with only the components you need!




回答3:


From here:

(...) web pages designed specifically for the iPhone should reduce the size of each component to 25 Kbytes or less for optimal caching behavior.

So, the obvious thing to do here is to "break down" your scripts and styles into multiple files of less than 25KB. You'd have to host them yourself then, obviously.




回答4:


You can get the whole build setup from github, remove widgets you don't need trom the manifest and build it then.

On linux - just use make

On Windows - you'll have to run the PHP build script



来源:https://stackoverflow.com/questions/6582083/removing-unused-jquery-mobile-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!