#How to mark path as external?
4 messages · Page 1 of 1 (latest)
In Astro, you can specify external paths in a few different ways depending on the context:
- For Stylesheets: You can use the
<link>element to load a stylesheet from an external URL or from your/publicdirectory. Thehrefattribute should be an absolute URL path. Relative<link>href values are not supported. Here is an example:
<head>
<!-- Local: /public/styles/global.css -->
<link rel="stylesheet" href="/styles/global.css" />
<!-- External -->
<link rel="stylesheet" href="<https://cdn.jsdelivr.net/npm/[email protected]/themes/prism-tomorrow.css"> />
</head>
(Source: Astro Documentation - Load a static stylesheet via “link” tags (https://docs.astro.build/en/guides/styling#load-a-static-stylesheet-via-link-tags))
- For JavaScript Files: If your JavaScript file lives inside of
public/, you can reference it by absolute URL path in your Astro component templates. Here is an example:
<script src="/some-external-script.js"></script>
If your external script lives inside of src/ and it supports the ESM module type, you can use an ESM import inside of a <script hoist> element in your Astro template:
<script hoist>import './some-external-script.js';</script>
(Source: Astro Documentation - How to Resolve JavaScript Files (https://docs.astro.build/en/guides/upgrade-to/v1#how-to-resolve-javascript-files))
- For Images: If you want to avoid any processing or to have a direct public link to your images, you can store your images in the
public/folder. You can also choose to store your images remotely, in a content management system (CMS) or digital asset management (DAM) platform. Astro can fetch your data remotely using APIs or display images from their full URL path.
(Source: Astro Documentation - Images (https://docs.astro.build/en/guides/images#_top))
Please note that the specific method to mark a path as external may vary depending on the context and the specific requirements of your project.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@quick zenith kapa.ai is still learning and improving, please let us know how it did by reacting below