Jump to content
Sign in to follow this  
j.silver

Browser Support for JS

Recommended Posts

Dear all:

I have just started learning js and jQuery. I am confused about browser support to js. On one hand, there seems to be a general agreement that js is the most popular language for website design. On the other hand, It's stated that js is not equally supported by browsers, especially old browsers, and that some user browsers might even turn down js. jQuery is a better alternative for browser support.

 

Is this true about problems in js' browser support? And if it is, how could a language with such a draw back become the most popular?

Share this post


Link to post
Share on other sites

All browsers support Javascript.

 

Javascript is a constantly changing language, so some new features are adopted sooner by some browsers than by others. You need to check whether the feature you want to use is supported by a browser or not. If the feature is not supported you need to find a workaround, or decide to not support that specific browser.

Share this post


Link to post
Share on other sites

Thanks, Ingolme. Is there a good and practical method of testing the feature that I want to use in old browsers and in cell phones and tablets? I mean a method other than downloading each and every old browser version for testing

Share this post


Link to post
Share on other sites

All browsers support Javascript.

There are browsers that don't support Javascript, but the people using those browsers will know it. Lynx would be one example.

Share this post


Link to post
Share on other sites

There are browsers that don't support Javascript, but the people using those browsers will know it. Lynx would be one example.

 

That's true but it's a really small demographic.

 

Either way, it is a good idea to build the site in a way that it still is useful even without Javascript because many people have add-ons to disable Javascript. If your application cannot possibly be built in a way that would still do something without Javascript, then just show a warning to the people indicating that Javascript is required to view the page.

 

There is no alternative browser scripting language to Javascript (Aside from the outdated VBscript used by old versions of IE). jQuery is just a program that was built on top of Javascript.

Share this post


Link to post
Share on other sites

and that some user browsers might even turn down js. jQuery is a better alternative for browser support.

 

Just to be clear, jQuery is still just JavaScript. jQuery is just a documented, cross browser tested, helpful collection of API's such that you don't have to figure out the unique browser differences yourself.

Share this post


Link to post
Share on other sites

 

 

There is no alternative browser scripting language to Javascript (Aside from the outdated VBscript used by old versions of IE). jQuery is just a program that was built on top of Javascript.

 

While jQuery is not a scripting language alternative to js, it does much of js' functionality without the complication associated with js programming. What are and where can I find a list of functionalities not yet doable by jQuery, but only by js?

Share this post


Link to post
Share on other sites

I doubt such a list exists, maybe jQuery has a feature request list that you can check to see what people are asking for. Personally, I don't use jQuery, I think it adds unnecessary bloat. It is many many times slower than doing the equivalent things in native code. It can be useful for more complex things like Javascript-based animation, but other than that I try to stick with native code. It's particularly bad when you see people including all of jQuery just so they can use something like $('#some_id'). Doing that is about 35 times slower than using document.getElementById with native code.

Share this post


Link to post
Share on other sites

When you state 'native code' in this subject, I presume you refer to js code. Is it so? You also brought an interesting subject about jQuery being slower than js, contrary to my assumption, which proves that one has to be careful about some information here and there in some tutorials. Do browsers give way to testing the speed of jQuery code against a similar code in js?

Share this post


Link to post
Share on other sites

A benchmark test is done by repeating the same operation over many times and counting how long it took. Here's an example:

var i;var element;var start, end;// Test JS speedstart = (new Date()).getTime();for(i = 0; i < 1000000; i++) {  element = document.getElementById("element");}end = (new Date()).getTime();var JStime = end - start;// Test jQuery speedstart = (new Date()).getTime();for(i = 0; i < 1000000; i++) {  element = $("#element");}end = (new Date()).getTime();var jQueryTime = end - start;// Display resultsconsole.log("JS time: ", JStime);console.log("jQuery time: ", jQueryTime);

Here are the results I got:

JS time: 4
jQuery time: 961

Share this post


Link to post
Share on other sites

By native code I mean vanilla Javascript, without using a framework like jQuery.

You also brought an interesting subject about jQuery being slower than js, contrary to my assumption

Why would a framework be faster? jQuery still executes Javascript code. Why would it be faster to use a framework to execute a piece of code instead of just directly executing that code? Anything that a framework does is slower than the equivalent native code. In the very best case, jQuery will execute the exact same Javascript code that you do (e.g., maybe there is an optimization in jQuery to detect if you are looking up an element based on the ID, and will just run document.getElementById in that case), but it will still have overhead because it needs to do things like checking what you're trying to do. In the very worst case it will use some ridiculously complex or slow method to do something that is fast if you do it natively.

Do browsers give way to testing the speed of jQuery code against a similar code in js?

Are you sure you understand what jQuery is? jQuery is a program that someone wrote using Javascript. It is not separate from Javascript. If you go and download the jQuery source code, it is Javascript code. It is not a separate language, it is a Javascript program. The browser does not understand "jQuery code" (there is no such thing), it understands Javascript. jQuery is Javascript, but Javascript is not jQuery. Javascript is a language, and jQuery is a program. Specifically, it is a framework to make some things in web development either faster or easier to program. Not faster to execute, faster to type. If you are running Javascript code then nothing can possibly be faster than just writing the native Javascript code. jQuery makes things easier for the programmer at the expense of performance.

Here are the results I got:JS time: 4jQuery time: 961

Yikes, 240 times slower.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...