#app.js loads before blade?
1 messages ยท Page 1 of 1 (latest)
That's impossible to answer without seeing your code. But in short, you need to load jQuery before you can use it
Vite would defer loading, so if you have a script block you can't access jQuery yet. You'd have to defer that script block as well
this is my app.js which is located in app.blade.php header and my blade.
So you're creating an inline script with that $(document).ready()? I guess you can add defer like <script defer>...</script> to make it load after the document has loaded. But yeah, you'd need to load that after your main script has loaded
Or use a non-jQuery method to wait for the document to be ready, e.g.
// Do your thing, if you have to
});
that was it @abstract hare. may I ask why does this happen?
But if you need to do stuff immediately, it may be better suited to go in app.js
Kind of beats the point of using jQuery, but yeah, that would work ๐
You used $, which is jQuery, before jQuery was loaded
Why? It's barely shorter to write $(document).ready(...) and much more confusing than the native event
Yeah, I know, but if you're just going to write plain JS you could as well not use jQuery imo. jQuery has some other fallbacks afaik, at least it did last time I used it
Yeah, I'm definitely all for not using jQuery at all today, there are much better packages for the specific non-trivial parts of it (e.g. xhr requests)