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:37
  • Consider situation in which 99% of your target consumer do not have javascript enabled in their browser and you write heavy javascript code in your website.
  • Also javascript runs on client machine with a very low priority which may slow down performance of your website.

And another one

  • All of your javascript code gets exposed as javascript is an interpreted language
查看更多
萌系小妹纸
3楼-- · 2019-06-18 05:39

I'd say there are a few possible downsides to using multiple libraries:

  1. Initial load time: you need to be a bit careful about your file sizes. For example, if that calendar you are using requires a whole separate library to function, you have to question why you're not just using the jQuery version.
  2. Client performance: you're offloading a lot of processing onto the client's computer, and older machines/browsers will struggle with particularly intensive scripting. This is a question of knowing your target audience though - if you're aiming at techies with monster PC's then you're more likely to get away with heavy scripting.
  3. Conflicts: as you say, there can be conflicts between the functions in different libraries. There are ways round this, but why give yourself the problem in the first place?

At the end of the day, all these libraries are just a different way of writing JavaScript. Pick whichever library works for you; the one that allows you to get the job done fastest and with the least errors.

查看更多
家丑人穷心不美
4楼-- · 2019-06-18 05:40

One aspect is that it can take time to load. If you have your scripts in included or linked files, that takes load time and more HTTP requests.

Also, more scripts can slow down the client computer. Many users nowdays have multiple pages or tabs open at once, and if yours is so heavy and slow that having other pages open at the same time makes things unstable on a base-level computer, then your website is probably a little excessive.

And finally, what if the user doesn't have javascript, or has it turned off? Will it totally break your site?

查看更多
别忘想泡老子
5楼-- · 2019-06-18 05:41

The answer is pretty obvious: more JavaScript means a bigger performance overhead. Depending on how you've structured your files, it might mean more HTTP requests, more data to load, more code to parse etc. If it's at all avoidable, you should pick a good framework (like jQuery) and stick with it, not mix and match them.

Performance aside, multiple frameworks also mean less maintainable code, because the maintainers have to be familiar with each framework to be able to work with them.

There are probably some exceptions, like using a general framework like jQuery together with a more specific one like Raphael, but usually that's solved by plugins.

查看更多
登录 后发表回答