views:

39

answers:

2

The user, when he clicks a link, needs to get my compressed html file that his browser will uncompress automatically, without any fuss. What must I do on the server side to accomplish this?

Thanks!

-- ben

+2  A: 

What server are you running?

If you have Apache, you can set up mod_deflate

quantumSoup
I see, thanks a lot. Here's the Apache mod_deflate doc: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
Pete Wilson
+2  A: 

I see now from your comment that you're literally trying to get compressed file to open transparently in a browser, not just compress the whole HTTP response.

That is definitely an issue for ServerFault. It relies on two things:

  1. The configuration of your HTTP server (it must be able to determine the appropriate MIME type and tell it to the browser, for most browsers the filename alone is not sufficient).
  2. The browser itself. There's no requirement that browsers be able to transparently open such a file, though many will if given the proper MIME type information.

(Original answer below)


I almost said this belongs on Server Fault, but I think the answer is needed on SO because it's not obvious it belongs on SF unless you understand the mechanisms at work, so:

In most cases, compressing HTTP responses is a capability of web servers, and you or your sysadmin will need to configure the web server (e.g. Apache with mod_deflate) to use that capability.

In the event that your application is its own web server, you need to review RFC 2616 (the HTTP/1.1 spec) and/or the documentation for any framework you're using.

I'm not exactly sure what the right thing is if you're using the webserver like as a reverse proxy... Probably still needs to be in the webserver, if it's possible at all.

Nicholas Knight
Aha! So the secret is that Apache has to do the compression while the file is on its way out?
Pete Wilson
@lcplben: See updated answer. There are two ways to handle what you're after, both require proper configuration of Apache or whatever other HTTP server is in use.
Nicholas Knight
I see. OK, thanks, Nicholas.
Pete Wilson
@Nicholas meaning that it's not enough to change .htaccess; httpd.conf has to be modified, I guess.
Pete Wilson