Question

I have a GZipped JavaScript file which I am encoding with a data:URI.

For example:

<a href="data:application/x-gzip;base64,FOO">My Javascript File</a>

When the user right-clicks and saves this file (in Chrome) I would like the resulting file's name to be download.js.gz. This way when the user double clicks this file (in Mac OS X), it gets decompressed and renamed correctly to download.js, and they can view the contents easily.

The problem is that when I use the content type text/javascript (or application/x-javascript), the file gets saved as download.js. And when I use the content type application/x-gzip, the file gets saved as download.gz.

Is there any way to get the file to be saved as .js.gz?

Here's a working example of both links: http://jsfiddle.net/xYm8w/3/

The file must be a data uri and not a link to an actual file. I tried changing the text between the <a> tags, but it doesn't affect anything at all.

Was it helpful?

Solution

There doesn't seem to be a way to do this in browsers besides Chrome. Therefore, the best option I could think of is to inform the user to save the file normally (so that it automatically inserts the proper extension based on the content type), and then having them go into finder and renaming the file to append the '.gz' extension.

On Chrome, though, you can use the download attribute of the <a> tag (which I found out by this answer). Example: http://jsfiddle.net/pYpqW/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top