0

I have a plain html file like so

<html>
    <head>
        <script type="text/javascript" src="script.js"></script>
    </head>
</html>

The script.js file is -

alert('hello');

I want to get the script.js in compressed form (either .gz or .zip) So, I compress the javascript file using 7-zp and get a script.js.gz. However, if I replace the above html to

<script type="text/javascript" src="script.js.gz"></script>

I get an error in firebug saying 'Illegal character'. Essentially, it is not deflating the javascript file.

Please note: I am aware of Apache mod-rewrite and additional javascript compressing techniques. However, I can't use any of that here, as I don't have that level of control on the server.

Can anyone help?

This answer in Stackoverflow gives something similar to what I'm looking for, but it gives information for Apache settings. I'm looking for the same for a plain html scenario.

3
  • 1
    You have to set the content encoding header for the file as gzip Commented Aug 26, 2012 at 6:57
  • Something tells me that you won't be able to minify or compress your script much further. Compression is only useful for larger scripts. You would probably save a few bytes if you embedded that script in your html file. If the script.js contents is just there as an example, then it would help if we could see all of your code. Commented Aug 26, 2012 at 8:14
  • Musa, how do I do what you suggest? I don't have access to the server. I can only upload content. Commented Sep 8, 2012 at 12:02

1 Answer 1

2

File compression is something you should leave to your webserver to negotiate with browsers (depending on the compression they support), which is why you found the SO answer referring to Apache settings. Doing it the way you are trying, the browser won't understand how to extract the script.js.gz file.

Compressing your script.js will actually result in a larger file than the original in this case as it is already so short.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm aware of that. I do not have access to the server. I can only upload content, not change server settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.