Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
Should I use import jQuery in a script if jQuery is being added manually?

I am maintaining an existing project, and I saw this:

The site is already including jQuery the traditional way (it's WordPress, and WordPress includes jQuery by default unless you change stuff).

<script src="cdn-or-local/jquery.js"></script>

And then the site is including another javascript file, which has been compiled with Webpack and Babel.

<script src="wordpress-theme/dist/whatever.js"></script>

On the original whatever.js file (not the compiled one, but the human-created one), it states:

import $ from 'jquery';

$(document).ready(() => {
...
}

And this confused me a lot.

As far as I know, if jQuery is already being loaded before the whatever.js file is loaded, then $ will already be defined.

Question: can I just safely omit import $ from 'jquery';?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, it's a good practice to import jQuery if your module needs jQuery - explicit declarations are good for readability, and will allow tooling to know what $ refers to! However, you can (should) configure webpack to not bundle jQuery as a dependency, but assume it is already loaded and available from a global variable.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda