What's the downside of using too much JavaScri

2019-06-18 05:07发布

I would like to know what are some downsides using too much JavaScript code in a web page?

For example, I will use a jQuery framework for my dropdown menus, tabs and accordion. And other JavaScripts for my calendar (even-though there is available calendar that uses jQuery) and other JavaScript for other stuff? What is the effect? (My opinion is conflicting of JavaScript and heavy to load)

I know a lot of developers that masters more than 2 JavaScript frameworks. My question is: When developing a project how do you pick a JavaScript framework for that project? Why will you use MooTools or jQuery for that project? (I know that is a matter of choice), but is there other reason? Like mootools is good for this... or jQuery is good for that..

I want to hear you opinion.

10条回答
不美不萌又怎样
2楼-- · 2019-06-18 05:22

It will depend on the browser (and back end) and how it performs /scales to many scripts. When developing a solution think about the audience's requirements first. Are they going to be running quad core monsters on super fast fibre optic links or small phones with a GPRS links. Then decide what technologies will fill those needs.

Don't start from the technology first.

查看更多
虎瘦雄心在
3楼-- · 2019-06-18 05:24

Network overhead. I'm not speaking about the scripts themselves, but about what they are doing:

Many plug-ins create frames to pull content from third party websites: Facebook like buttons, comments, Twitter feed, Google and various kind of ads, etc. And moreover these plugins may load and run their own script stuff too.

Even if you have 8 cores, the website content is jumping around for at least 30 seconds as plugins load their content (on every page visit!). That's why I installed browser plugins to block javascript for good. But even if I enable them it's common that they pull scripts from at least 20-30 domains, and I need to enable all scripts on the page 4-5 times to make the site fully functional. Please avoid creating situations like this.

查看更多
放我归山
4楼-- · 2019-06-18 05:26

From your question, a couple of issues come to mind:

  • Having a lot of little script files can be a performance problem. If you're going to use a lot of different scripts, combine them into one script file (and minify it and serve it with gzip compression). There's a tip related to this on the unofficial Prototype & script.aculo.us wiki (disclosure: I mostly wrote that tip, but with a lot of input from smarter people). Also look at whether you can leverage CDNs (most frameworks are now available via the Google CDN, for instance).
  • Having lots of different frameworks (jQuery, Prototype, MooTools, YUI, etc.) in the same site can become a skills issue -- anyone working on the site will need to have skills in various different frameworks.
  • Some frameworks are incompatible with one another (for instance, I doubt Prototype and MooTools can currently co-exist on a page; jQuery and Prototype can via jQuery's "no conflict" mode).

In terms of choosing a single framework, look at what you're trying to do -- some frameworks will better suit some sites than others. Also look at the skillsets your developers already have, as the less new stuff they have to learn, the more time they can spend building your site. Look at the community around the framework. Consider the availability of plug-ins (although there are a lot of low-quality plug-ins out there; don't judge by quantity alone). Look at whether the API of the framework sits well with your approach to things.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-06-18 05:27

What are some downside using to many JavaScripts in a website?

  • HTTP overhead
  • Low maintainability

Why will you use MooTools or jQuery for that project?

This is not just a matter of personal taste. Check out this question for more details.

There are specific frameworks out there for specific things--Take Ext JS for example, which tries to encompass everything a site needs. This is not what jQuery does.

查看更多
姐就是有狂的资本
6楼-- · 2019-06-18 05:34

Don't also forget that some users may have Javascript disabled, so having some of the required features of the website (ie menus, navigation, forms etc) JS based will result for those users to be unable to view your site.

查看更多
我只想做你的唯一
7楼-- · 2019-06-18 05:36

Using a lot of JavaScript files shouldn't be a problem since you can always merge them all together to minimize HTTP requests. Of course to execute all that JavaScript it takes browser's time. There's also chance that there will be conflicts between all those JS libraries/plugins or within DOM.

As for choosing the right library it really depends on what kind of site/application you are making. If you just want to use pre-made plugins then there's isn't a big difference which library you use and you should just chose the one which has more of the plugins you want to use and I'm quite sure that jQuery is the best choice here since it has the most plugins overall.

From other hand if you want to write your own components/plugins/code then you should test each of them out and see which one suits your coding style and project the best. For example a while ago I found Prototype suits my taste better and is quite nice for big JS heavy projects. But jQuery has gone a long way since then so I'd probably try each of the most popular libraries out if I had to make a new project.

查看更多
登录 后发表回答