How to Serve AWS S3 Gziped Webpacks

I need to serve the webpack package (and derivative assets) from AWS S3, and I want to serve these Gziped files if the browser supports it. S3 does not update the contents of Gzip on the fly, so you need to download both uncompressed and compressed versions of your assets and implement the logic to select the appropriate version from the client side.

Now, when I serve the html page from my server, I can choose to download the file main.bundle.jsor its compressed version main.bundle.js.gz, depending on the header Accept-encodingin the request.

The problem is that webpack does not know anything about the version of my Gziped assets, so it continues to load the remaining pieces of packages with uncompressed files.

Is there any way to tell webpack to load pieces of packages and other files by adding a suffix to their paths (in this case .gz)?

The only solution I can think of is to create two separate packages: one for uncompressed files, and the other for gziped, with different ones publicPathto distinguish them. But I think this may be redundant, as these two bundles will be almost identical.

Any thoughts?

Thanks!

+4
source share
1 answer

If you include CloudFront in your S3 bucket, they recently (12/17) just added the gzip option. See: https://aws.amazon.com/blogs/aws/new-gzip-compression-support-for-amazon-cloudfront/

+2

Source: https://habr.com/ru/post/1607447/


All Articles