usually, if plaintext is compressed, there must be decompre开发者_StackOverflow中文版ssion routine. How does js engine interpret minified compressed js scripts??
Does js engine have built-in deminification algorithms??
it does not need to be decompressed, minified code is still javascript, its just harder for humans to read.
First, you need to understand that there is a difference between minification and compression.
1. Minification does not compress
Minification is the process of reducing JavaScript to as few bytes as possible, by removing extra whitespace, changing variable names to shorter ones, etc. The encoding and characters of the file remain the same. Since a minified file doesn't actually change the encoding or functionality, nothing is needed to convert a file back since nothing really changed.
2. Compression changes a file
When you compress a file, say using gzip, you are re-encoding the data of a file or stream into a different encoding that takes up less space. It is in this instance where a decompression routine is needed to translate the file back to its uncompressed state. When uncompressed, the file returns to its original state.
3. Browsers use a combination of compression and minifcation to achieve as small of a bandwidth footprint as possible.
What's great about minification and compression is that they ARE two separate processes that do two separate things, and they can be combined to deliver as small a file to the browser as possible. For example, the original jQuery source right now is well over 200K, but through minifcation AND delivering the file compressed, it only takes ~30K of bandwidth to deliver to the browser.
Minified javascript is still javascript. Think of it as removing the white space and renaming long variable to shorter variable.
Minified JavaScript is simply that same code, but abbreviated (e.g. var foobar = 2 may before var a=2;)
GZipped JavaScript files (and other static files) are genuinely compressed, and do indeed get decompressed by the client machine before the engine uses them.
The browser will identify to the server that it can access zipped content by a header similar to
Accept-Encoding: gzip, deflate
精彩评论