Compress required external js files
Asked Answered
S

1

5

I am using Gtmetrix to test my page load time. I enabled gzip compression on my site by adding code to .htaccess

.htaccess code:

<ifModule mod_gzip.c>

mod_gzip_on Yes

mod_gzip_dechunk Yes

mod_gzip_item_include file .(html?|txt|css|js|php|pl)$

mod_gzip_item_include handler ^cgi-script$

mod_gzip_item_include mime ^text/.*

mod_gzip_item_include mime ^application/x-javascript.*

mod_gzip_item_exclude mime ^image/.*

mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

</ifModule>

but still Gtmetrix showing the below warning

Compressing http://s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js could save 453.6KiB (71% reduction). This is an external js file. How can I compress this?

Siderostat answered 5/7, 2016 at 6:0 Comment(0)
V
7

Since browser requests for that file do not pass through your web server but rather go directly to s3.amazonaws.com, the short answer is: you can't.

However, you could download the file and put it on your web server and change the corresponding references in your HTML to load it from your site instead of from s3.amazonaws.com.

There is no reason why the file is not available in compressed format from Mailchimp but since they have not done so, you will need to serve it from your webserver to achieve compression.

Vigen answered 12/8, 2016 at 16:8 Comment(2)
That seems like an option, but have in mind that if MailChimp change anything in there original script you will have to update your local copy or if you stick with older version you risk to loose integration with that service.Mountaineer
If you want to get fancier, you can create a caching/compressing origin CDN server like CloudFront which uses the Mailchimp S3 bucket as the origin and serve it via that. So long as they update the same file and you don't set your caching too long, you'll receive updates. If the URL changes to the underlying file, you won't see those updates.Vigen

© 2022 - 2024 — McMap. All rights reserved.