Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashed build assets end up in multiple places in build output #5502

Closed
1 task
delucis opened this issue Nov 30, 2022 · 6 comments
Closed
1 task

Hashed build assets end up in multiple places in build output #5502

delucis opened this issue Nov 30, 2022 · 6 comments
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@delucis
Copy link
Member

delucis commented Nov 30, 2022

What version of astro are you using?

1.6.12

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

macOS / Stackblitz

Describe the Bug

Astro outputs various assets from its build and adds a hash to the file names to help with immutable caching. Currently these end up in various places making it less simple than it could be to set up cache headers for static builds:

  • dist/assets/<name>.<hash>.css

    • styles in <style> tags or imported as ES modules
  • dist/chunks/<name>.<hash>.js

    • scripts from UI integrations (Preact in this reproduction)
    • code-split modules (dynamically imported canvas-confetti in this repro)
  • dist/hoisted.<hash>.js (also dist/client.<hash>.js?)

    • hoisted scripts from Astro components (if they’re bigger than Vite’s size limit for inlining — forced in the reproduction using vite.build.assetsInlineLimit)
  • dist/<ComponentName>.<hash>.js

    • code for hydrated framework components

Proposal here is to move these all under assets/ so that caching is simpler to set up. Vercel automatically sets immutable cache headers for the assets/ folder of static Astro sites, so this would also ensure their default set-up covers everything.

Alternative would be to make PRs to Vercel and other providers for a more complex immutable caching set-up.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-p5qbcj?file=src/pages/index.astro

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp added the - P3: minor bug An edge case that only affects very specific usage (priority) label Nov 30, 2022
@JerryWu1234
Copy link
Contributor

JerryWu1234 commented Dec 7, 2022

I want to confirm one thing with you.
Could I move all these files to the folder assets could fix it?
like this
image

@JerryWu1234
Copy link
Contributor

I want to try fix this bug

@delucis
Copy link
Member Author

delucis commented Dec 7, 2022

I think that’s one option, sure — or just move the contents of chunks/ into assets/. And we’d also need to make sure generated links to CSS, etc. end up pointing to the new location too.

@JerryWu1234
Copy link
Contributor

I think that’s one option, sure — or just move the contents of chunks/ into assets/. And we’d also need to make sure generated links to CSS, etc. end up pointing to the new location too.

let me try to move all to the assets folder

@JerryWu1234
Copy link
Contributor

I think that’s one option, sure — or just move the contents of chunks/ into assets/. And we’d also need to make sure generated links to CSS, etc. end up pointing to the new location too.

I have tried these files moving But following your said method that doesn't move the CSS bundle file.
So, When do I need to pay attention to the CSS link?

JerryWu1234 added a commit to JerryWu1234/astro that referenced this issue Dec 12, 2022
natemoo-re pushed a commit to JerryWu1234/astro that referenced this issue Jan 5, 2023
natemoo-re pushed a commit that referenced this issue Jan 5, 2023
* feat: change path

* feat: fix bug #5502

* fix: astro fix to patch

* feat: change to major

* chore: update changelog

* fix: change entryFileNames into assets folder

* fix: fix error message in test

Co-authored-by: bluwy <[email protected]>
@Princesseuh
Copy link
Member

Fixed in 2.0 with the _astro folder!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

4 participants