JQuery and Chrome Extensions

Can jQuery be used as a JavaScript library in Chrome extensions? jQuery and other DOM libraries are designed to hide the differences between browsers, and since I only configured on Chrome, should I use it?

+7
source share
4 answers

There is no reason not to use jQuery on one of your extension pages (background, popup, options, etc.). You should always use a local copy of jQuery, but not download remotely hosted via http.

I would advise against introducing jQuery as the contents of the script, if possible. If you only need a simple selector or event listener, injecting about 100 kilobytes of js code every time you visit the page is a bit overkill.

+8
source

I use it for my Chrome extensions, and I think it is very smart. jQuery is more than just hiding differences. It is full of functions that make it possible to code faster and more reliably. There are many extensions that allow you to extend your scripts. I think you will be ill yourself, not using it!

+3
source

In addition to coding faster and β€œDon't reinvent the wheel (unnecessarily)” - there may come a time when you need to work on something other than Chrome extensions.

jQuery makes it easy to reuse these efforts on other platforms or in different circumstances.

Finally, using the standard library, others can more easily: help, improve, or simply trust the code. (It will not be just yours, forever, if it is good.)

0
source

No, you should not use jQuery in Chrome extensions.

jQuery is quite large, and the vast majority of it supports other browsers, that you just don't need to worry about in the extension.

For example, you do not need the Sizzle engine at all (use document.querySelector ), although it is really valuable in IE6-8, you do not need standard event handlers, because you will not support IE or Opera at all (use element.addEventListener ). You don't need jQuery delayed when Chrome supports Promise natively . You do not need $.ajax if you have fetch . There are many more .

In addition, jQuery does not support many modern functions, for example, you cannot use passive event handlers or load scripts asynchronously (it does not even support defer ).

As the currently selected answer shows, jQuery is expensively injected. This is worth optimizing right down to what you need with minimal code.

As a rule, with any extension of the toolkit (jQuery, Underscore, etc.) they always start without them and only bring them if you think you need them. If you find that you need infrastructure, consider more modern ones that use new features (which you can rely on to be present in Chrome), rather than those designed to standardize code between browsers. Think about what you need from the framework - if it's just what you know and how jQuery is, then it's good (getting to know you can be an excuse if it will be useful for you or your team to learn new things), but you should know this costs injection and execution.

jQuery is an exceptionally successful toolkit with broad support, it just isn't suitable for an extension only for Chrome.

-one
source

All Articles