Are there "problems" using jQuery’s small?

Asked

Viewed 81 times

2

For example, some parts of a site, I can not fully touch the HTML, put the platform blocks for "security" and does not let modify, so I use jQuery/Javascript to make the modification I need. Does this interfere with the performance of the site? Much or little?

Example of a code I used now, just to insert an image:

$j('<img src="http://i.imgur.com/UgaMSoE.png" style="max-width: 1.5rem;"/>').insertBefore('section#desejos .mywish__header a svg');

I use codes like this from time to time (not many, only once in a while), when you can’t modify something I need. This influences the website’s performance A LOT?

Do you have any problem using "small" codes in jQuery/Javascript?

  • 1

    Think of everything you’re doing with jQuery, it’s being converted to javascript behind the scenes. Its use is recommended to make code smaller and cleaner in medium and large projects. But adding an entire library to not use one or two lines of pure javascript in your project, in addition to a bad practice, becomes laziness. Because it wouldn’t be hard to find the same code on the internet in pure javascript!

2 answers

5


Yes, there are SEO problems. Today charge time counts for the page to be well ranked in search engine.

This alone should be something to think about using jQuery. Even more to make a single line to do something that can be done the same or simpler without jQuery.

Much does not interfere with overall performance, but interferes.

The only way to know if it counts for your case is to do and test.

0

Can use without fear. This will not influence the performance, there is only an initial overload on the first load, where the file Javascript of jQuery that will be loaded. After this, the file will already be cached and there will be almost 0 cost of download.

Just make sure to use minified files in production, thus reducing the bandwidth required for download of these archives.

In cases where it will only make a small change via jQuery, try to use Javascript pure instead of carrying the jQuery just to insert a piece of content into the page for example.

Below an insert code of HTML on the page with pure javascript:

var newItem = document.createElement("LI");       // Create a <li> node
var textnode = document.createTextNode("Water");  // Create a text node
newItem.appendChild(textnode);                    // Append the text to <li>

var list = document.getElementById("myList");    // Get the <ul> element to insert a new node
list.insertBefore(newItem, list.childNodes[0]);  // Insert <li> before the first child of <ul>

This example was taken from W3schools website:

** Edited **

In the matter of SEO, you must put files Javascript at the bottom of the page to prevent file loading from blocking the page, thus generating delay in loading the site. You can even ask Google for an analysis to check the site and have some instructions to improve it. Clicking here you go to the analysis site of Google.

  • In case, use the code on the body and not on Heady, right? Pro SEO.

  • It is better to use pure Javascript even though it is "bigger" than using Jquery?

  • 1

    This is not true, jQuery does a damage to the overall performance. Whether or not this performance is necessary is another story in general is not. But it can be measured.

  • 1

    Lucas, correct, use at the end before closing the body. About what the bigown said, there is an overhead in the use of jQuery, because it is the javascript encapsulated, so that "we use shortcuts" to actually run a pure javascript code. Currently, the overhead that generates I would not worry, virtually all sites today pussem libs in javascript and not even so we noticed such effect. A site to compare pure javascript code vs jquery would be: https://jsperf.com/jquery-vs-javascript-performance-comparison/22

  • 1

    If almost 1000x slower doesn’t matter, then it’s good.

  • bigown, of course it’s important, but these tests run for millions of executions. In this environment, no doubt pure javascript, but when you have small interactions, for the human is imperceptible.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.