Skip to content

Loading chunks from CDN with precompiled assets #2219

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

Closed
lavaturtle opened this issue Aug 7, 2019 · 6 comments
Closed

Loading chunks from CDN with precompiled assets #2219

lavaturtle opened this issue Aug 7, 2019 · 6 comments
Labels
support Questions or unspecific problems

Comments

@lavaturtle
Copy link

In our app, we precompile assets, and use the same assets on staging and production environments. Also, we use a different CDN on staging vs. production environment.

The pack .js files load correctly from the CDN, but the chunks are then loaded from our app instead of from the CDN. Is there any way to configure things so the chunks come from the CDN as well?

We considered setting WEBPACK_ASSET_HOST during precompilation, but this would require hard-coding one CDN or the other, when we in fact want it to be environment-dependent.

(This may be similar to #1782 but I'm not sure if that one has already been addressed.)

Thank you!

@woodhull
Copy link

woodhull commented Aug 7, 2019

Interesting. I work with @lavaturtle and #1782 also may be an issue for us since we have some customers who consume our product as a self-hosted docker image. It may only happen to work so far because none of them have a CDN.

It seems like the ideal behavior is to load chunks relative to the pack file always? Rather than relative to the app root?

The current behavior is not the complete end of the world (our app can serve the files most of the time, just slightly slower), but it would be better if everything always loaded from the CDN. It can lead our users to sometimes experience chunk 404s while deploys are rolling out across our fleet. If everything was loading from the static asset CDN the old pack chunks would be live on the CDN even after new code had been deployed.

@woodhull
Copy link

woodhull commented Aug 7, 2019

For what it's worth we're running Webpacker 4.0.7 with webpack 4.39.1

@jakeNiemiec
Copy link
Member

jakeNiemiec commented Aug 7, 2019

we have some customers who consume our product as a self-hosted docker image. It may only happen to work so far because none of them have a CDN

The public_root_path & public_output_path are locked at build time. This is, unfortunately, a webpack limitation. There are ways to make this dynamic, but this is outside of webpackERs capabilities. I recommend setting up the containers to compile assets themselves. That way, the customers who consume your app can use your CDN.

If everything was loading from the static asset CDN the old pack chunks would be live on the CDN even after new code had been deployed.

Having old pack chunks on the CDN probably would not be an issue since the file/chunk names are hashed by content.

Apart from all that, if there's a new feature that you want to see added, you'll need to write the code yourself. You can also send feature ideas in an email to the rails-core mailing list. Hope this helped.

@woodhull
Copy link

woodhull commented Aug 7, 2019

I don't think you actually read this very thoroughly.

Packs and chunk requests going to different hosts is the expected behavior? Okay! 🤷‍♂

@woodhull
Copy link

woodhull commented Aug 7, 2019

All we want is to load chunks relative to the pack that was generated.

This might not be possible I guess.

@jakeNiemiec
Copy link
Member

All we want is to load chunks relative to the pack that was generated.

Like I said if you precompile packs before they are distributed as docker images, public_root_path & public_output_path are locked, they can not change dynamically. As you said, you can probably get away with statically defining your CDN when you precompile the packs before saving the docker image.

If you want to troubleshoot the issue, please post some example files to a gist.github.com (or, even better, an example repo) and hopefully I can be more specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions or unspecific problems
Projects
None yet
Development

No branches or pull requests

3 participants