how to link external css and js in laravel 8/9 jetstream inertia js

Viewed 709

I am working on a laravel 8 project for learning purposes. I am new in jetstream, inertia.js here I can not understand how to add or link external CSS/js files in innertia.js.

Someone, please help me.

3 Answers

you can just add this on the main page layout :

        <script src="{{ asset('js/data.js') }}"></script>

then add your js file in this path : public/js.yourfile.js

// Layout.vue

import { Head } from '@inertiajs/inertia-vue3'

<Head>
  <title>My app</title>
  <meta head-key="description" name="description" content="This is the default description" />
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<script src="your script location"></script>

</Head>

// About.vue

import { Head } from '@inertiajs/inertia-vue3'

<Head>
  <title>About - My app</title>
  <meta head-key="description" name="description" content="This is a page specific description" />
</Head>

Actually, there are many ways to link CSS/JS Here I share a very simple way to link

first, you have to store your external file in the public directory for your project.

then in your index file

("asset" automatically locate public folder that's why you don't need to mention that.)

Note: same process for CSS file.

Related