Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reason the YUI compressor replaces single quotes with double quotes?

As the title says: What is the reason the YUI compressor replaces single quotes with double quotes? Do double quotes take less space (I don't think so)? Or is it something else?

like image 264
PeeHaa Avatar asked Dec 27 '22 06:12

PeeHaa


1 Answers

Normalizing these chars to one type better enables GZIP compression, why it happens to be double quotes is coincidental.

GZip works the standard way compression might, so for instance if you have a string such as:

"Foo", 'bar', "baz"

You could compress ", as a single charecter (lets use the # sign to represent that), reducing the string to something such as:

"Foo#'bar', "baz"

On the other hand, if you had:

"Foo", "bar", "baz"

You could compress ", "b it such as:

"Foo#ar#az"

Thus leading to a shorter string by eliminating the total number of chars available.

Again, making it a either quote doesn't matter, just as long as it's consistent.

Here's a cut+paste from my linux command line that demonstrates it:

briang@ubuntu:~$ cat 1.txt
"Foo", 'bar', "baz"

briang@ubuntu:~$ cat 2.txt
"Foo", "bar", "baz"

briang@ubuntu:~$ cat 1.txt.gz
&▒:O1.txtSr▒▒W▒QPOJ,R▒QPJJ▒R▒(▒P▒

briang@ubuntu:~$ cat 2.txt.gz
<▒:O2.txtSr▒▒W▒QPJJ,▒PUJ\tE▒

briang@ubuntu:~$ ls -la *txt*
-rw-rw-r-- 1 briang briang 20 2012-02-14 16:39 1.txt
-rw-rw-r-- 1 briang briang 46 2012-02-14 16:37 1.txt.gz
-rw-rw-r-- 1 briang briang 20 2012-02-14 16:39 2.txt
-rw-rw-r-- 1 briang briang 41 2012-02-14 16:38 2.txt.gz

You can see gziping such small files adds size rather than reducing them, but looking at the gzip differences between the two raw inputs gets the concept across. The normalized gzip file is smaller by 5 bytes.

like image 191
Incognito Avatar answered Jan 26 '23 21:01

Incognito