My question is why. Why use .html when you can use friendly URL's instead?
Anyways, technically, you could but the important thing that determines how the browser handles the data is the HTTP content-type header.
In a standard HTML document, the content type header will contain at least this:
Content-type: text/html
Some may go as far as this in order to specify the character encoding of the page:
Content-type: text/html; charset=UTF-8
With regards to serving gzipped html pages, the proper way to do it is to first compress the HTML in a gzip format, then output the compressed data after the usual HTTP headers including the following headers at minimum:
Content-type: text/html Content-Encoding: gzip
For browser compatibility, you can also include:
Vary: Accept-encoding
That way, you can serve compressed and uncompressed content. Here's code in php to help you understand things better. Feel free to save it as a file with a PHP extension, and yes the compression will still work:
<?php $myhtml=file_get_contents("/path/to/plain/uncompressed/htmlfile.html"); header("Content-type: text/html",true); header("Vary: Accept-Encoding",true); if (strpos(strtolower($_SERVER['HTTP_ACCEPT_ENCODING']),"gzip") > 0){ //browser supports gzip header("Content-Encoding: gzip",true); $myhtml=gzencode($myhtml,2); } header("Content-length: ".strlen($myhtml),true); flush(); echo $myhtml; exit(); ?>
First, a file is fetched locally in the server and the contents of it are stored in a myhtml variable. Next, the minimum headers are prepared. Then the system checks to see if browser supports gzip extraction by checking the incoming accept-encoding header. If it does, then the gzip encoding HTTP header is prepared and contents are myhtml are then compressed. Finally, regardless of the support for gzip, the length of the document is based on the number of bytes of the contents of myhtml. Finally its printed on screen.
.peanutbutterjellytimeif you like.... as long as the MIME type is process corrected. GZIP in browsers will deflate the file before processing, meaning its still the original format to the end-user.