Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
Jquery is not defined when remove "text/javascript" attribute

Scenario that works:

  • I have an APP_FRAMEWORK.JS file that was generated through a WEBPACK, including BOOTSTRAP AND JQUERY inside it.

    <script type="text/javascript" src="{{ asset('js/app_framework.js') }}" defer></script>
    
    @if(!empty($assets['js']))
        @foreach ($assets['js'] as $js)
            <script type="text/javascript" src="{{ asset($js) }}"></script>
        @endforeach
    @endif
    

If I load the page as in the example, it works perfectly, without any errors in the scripts that are loaded inside that loop below.

My question:

  • Why, if I remove the "text/javascript" when loading the MAIN SCRIPT (APP_FRAMEWORK.JS) the $ is not defined error starts to appear?
  • Remembering that this TYPE is no longer mandatory, scripts are loaded in the correct order and there is a DEFER!!!

enter image description here enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. Forcing the browser not to load scripts from cache (SHIFT + RELOAD on Mac) enter image description here Just by doing that, we already see that the APP_FRAMEWORK.JS is being loaded after the others.

  2. Another point, defer does not prevent other scripts from being loaded until those that have it defined carry out their process. The definition of the defer attribute goes further, being:

    The defer attribute tells the browser to run the script only when the HTML parsing is finished. The script will be requested asynchronously, its download will be completed and, only when the analysis of the HTML document is finished, will it be executed. Even if the full script download happens before the full HTML parsing, it won't run until later. If you have multiple script elements with the defer attribute, they will be requested in parallel and executed in the stated sequence.

  3. As the scripts are at the bottom of the page, there is no need to use defer, as it will never stop interpreting the HTML to download any JS.

  4. The problem itself has nothing to do with type="text/javascript", everything is related to the size of the loaded scripts, download time, in view of the order of dependency and execution.

  5. If you really need to follow a JS loading order, defer must be used in all <script defer>, so that it follows the declared sequence, thus:

<script defer src="{{ asset('js/app_framework.js') }}" defer></script>
<script defer src="{{ asset('js/app.js') }}"> others ...</script>

@if(!empty($assets['js']))
    @foreach ($assets['js'] as $js)
        <script defer src="{{ asset($js) }}"></script>
    @endforeach
@endif

enter image description here

Refer link: https://www.braziljs.org/p/diferencas-entre-async-e-defer

And now comes the question that doesn't want to shut up... Why, even loading the files from the cache in the correct order, the browser displayed the message?

Has anyone heard of error cache from the browser based on those files? Like, see that the scripts are the same, that the last execution of those scripts gave an error and already display the error automatically?

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda