Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Where should I put my javascript


Hello I see you there the theme has lots of helpers for loading javascript in various ways.

i'm using Laravel

My first question is where would I put my javascript for single pages.

My second question is where would I put my Java script for app wide use.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)


Hi,


To load JavaScript files in your Laravel project, you can use the Laravel Mix tool that comes with the starter template. Laravel Mix is a wrapper around Webpack that simplifies the process of compiling and bundling your assets.

There is no fixed rule for where to put your JavaScript files, but you can follow some conventions based on your needs.

- For global JavaScript files that you want to use in every page, you can add them to the `/starterkit/resources/mix/scripts.js` file. This file will be compiled and output to the `public/js` folder. You don't need to include it manually in your Blade layout file, because the starter template already does that.

- For page-specific JavaScript files that you only want to use in certain pages, you can create a separate file for each page and add them to the `/starterkit/resources/mix/vendors` folder. This folder will be copied to the `public/assets/plugins/custom` folder without any compilation. You can then include them in your Controller file using the `addJavascriptFile` helper function, like this:


addJavascriptFile("assets/plugins/custom/my-page.js");


I hope this helps.

Thanks


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(