For what reason does the YUI compressor replace single quotes with double quotes?

As the name says: What is the reason that the YUI compressor replaces single quotes with double quotes? Double quotes have less space (I donโ€™t think so)? Or is it something else?

+4
source share
1 answer

Normalizing these characters to one type better allows GZIP compression, which is why double quotes are a coincidence.

GZip works in a standard way of compression, therefore, for example, if you have a line, for example:

"Foo", 'bar', "baz"

You can compress ", as one charecter (allows you to use the # sign to represent this), reducing the line to something like:

"Foo#'bar', "baz"

On the other hand, if you have:

"Foo", "bar", "baz"

You can compress ", "b it, for example:

"Foo#ar#az"

Thus, leading to a shorter string, excluding the total number of characters available.

Again, if you make this quote, it does not matter, as long as it is consistent.

Here we cut out + paste from my linux command line, which 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 that gziping such small files adds size, not reduces them, but looking at the differences in gzip between the two source inputs, the concept becomes clear. The normalized gzip file is 5 bytes less.

+10
source

Source: https://habr.com/ru/post/1396477/


All Articles