Summer Sale! All accounts are 50% off this week.

p0t4t0's avatar

How do you import jQuery into a Laravel project properly?

Does a fresh installation of Laravel already come with jQuery or do I have to install it with npm or something? In my public/js folder I created a script.js file and tried alerting something but it didn't work. So in my footer.blade.php I imported jQuery via CDN as well as importing my script.js file with <script src="{{asset('js/script.js'}}"></script>and although it works, I can't help but feel this is redundant.

Also, I installed https://craftpip.github.io/jquery-confirm/ to my Laravel app with npm and couldn't get it to work.

0 likes
6 replies
jlrdw's avatar

I only use jquery for some small things, and I don't use mix. So I just put it at top of template if it will be used in that view:

<script type="text/javascript" src="<?php echo asset('assets/js/jquery.js'); ?>"></script>

And put the actual script at bottom of view page.

p0t4t0's avatar

But what if I use jQuery instead of Vue? For the reason being I haven't yet a good grasp of Vue. Also, when installing plugins with npm install, how do I bring it into my application?

p0t4t0's avatar

@jlrdw

<script type="text/javascript" src="<?php echo asset('assets/js/jquery.js'); ?>"></script>

doesn't seem to work

p0t4t0's avatar

I just read it. Thanks but one more question though. Where should I store gulpfile.js? I installed the plugin I mentioned earlier as well as jQuery with npm install.

jlrdw's avatar

Sorry I don't use that but perhaps search forum for gupfile.js.

Please or to participate in this conversation.