-
Notifications
You must be signed in to change notification settings - Fork 265
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
Serve assets from different domain in development #2078
Conversation
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
I've come to the realization that serving assets from a different domain in development is not that useful anymore now that we are on Vite. The original reasons to do this is because the Classic Remix Compiler didn't have clever resolutions for assets, especially for CSS. Assets would work in development and later break in production so we had to "break" development as well. However, I think we are in a better place now:
There are also a few cons to separating assets in a different server:
At first I thought the benefits (i.e. making dev more similar to prod) outweighed the cons but after realizing that the problems we had with the Classic Remix Compiler are now mostly solved... I think it's not worth the extra complexity this adds anymore. Open to discussions, though, since I might be missing some of the benefits of serving from a different domain. |
This serves assets in Vite like CSS / images from
localhost:9100/mini-oxygen/00000/11111/22222/33333/...
to mimic production, just like we used to do in the classic compiler.However, JS assets generated from Remix are still served from
localhost:3000/...
because Remix does not check Vite'sserver.origin
.Therefore, for now at least, we only serve non-JS assets from a different domain, which is the main thing we want to mimic.
For the record, a partial fix in Remix would look like this:
That said, I'm not sure serving JS from a different domain is desirable because these are development chunks, which will be different in prod. Plus, the user probably doesn't need to point to JS chunks manually so there's not possible confusion / error to be made, unlike when pointing to images or CSS.
This works also for
url(...)
in CSS:Prod build:
Development:
There's an issue with
server.origin
in Vite's HMR. I'm working on a separate PR to the Vite repo to fix that.Right now, even though we serve files initially from
9100/mini-oxygen/extra-path
, HMR for asset files start importing from9100
root without keeping the path.