#app.js loads before blade?

1 messages ยท Page 1 of 1 (latest)

odd torrent
#

how do I solve this?

abstract hare
#

That's impossible to answer without seeing your code. But in short, you need to load jQuery before you can use it

cyan spindle
#

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

odd torrent
#

this is my app.js which is located in app.blade.php header and my blade.

cyan spindle
#

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

abstract hare
#

Or use a non-jQuery method to wait for the document to be ready, e.g.

  // Do your thing, if you have to
});
odd torrent
#

that was it @abstract hare. may I ask why does this happen?

abstract hare
#

But if you need to do stuff immediately, it may be better suited to go in app.js

cyan spindle
abstract hare
#

You used $, which is jQuery, before jQuery was loaded

abstract hare
cyan spindle
abstract hare
#

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)