Replies: 2 comments 2 replies
-
Could you expand on how 'things' are 'imported somehow'? This proposal seems to hinge on this, and so I would like to understand it better. I expect the answer will either strengthen the proposal or negate it! |
Beta Was this translation helpful? Give feedback.
-
I think it may help to look at Fonts, Images, and Icons at the same time to answer this question, since each has a different set of requirements. For example:
I spent some time last night digging into this more, and wrote up some thoughts. This is where I landed: https://gist.github.com/FredKSchott/77e03f1427d28b1d00d830d926a1c18f Main takeaway was that the real question to answer first is how we want to reference these assets in our code. This proposal assumes that dynamic references are correct, but I believe there might be some real flaws with the approach. Every other SSR-powered build tool that I know of uses ESM imports for asset references (or absolute URLs when a dynamic fallback is needed). I think we need to better understand why:
pros & cons of static vs. dynamic:
There's also the If we moved to a static reference like |
Beta Was this translation helpful? Give feedback.
-
Problem
Astro currently has 2 categories of files in its file structure:
src/
get built byastro build
and placed indist/
as they are used. However, with the static build (and more importantly, SSR), we can only build things that are statically linked; ie things that areimport
ed somehow.public/
are copied as-is and never touched by the build pipeline.However there's a 3rd category of files that we don't have a good solution for. These are files that need to be transformed at runtime by components things. Use cases include:
Astro.fetchContent
.Proposal
I propose we have an
assets/
top-level folder that is a sibling ofsrc/
andpublic/
. It is likepublic/
but with these differences:public/
you cannot directly load a file fromassets/
in the browser (in dev or prod). It is not exposed to the web server.dist/server/
(bikeshed) folder to be used at runtime in SSR and in the static build.Components will have access to this folder through these APIs:
Build-time transforms
if you only need to build the file once, such as SSG a markdown file, use
load
which loads a file from theassets/
folder.Runtime transforms
assets/
, in production it isdist/assets/
(bikeshed). A cacheKey is provided so that it can look to see if the file is already transformed in the.cache/
folder. If not the 3rd argument, transformer function is called.During the build the
.cache/
folder is copied todist/.cache/
if using SSG anddist/client/.cache/
if using SSR.Filenames will be hashed to allow forever cache headers.
Beta Was this translation helpful? Give feedback.
All reactions