Is there any other reason to compress Javascript in the source code besides getting smaller?

Asked

Viewed 118 times

3

Most libraries come with the compressed code as follows

<script>(function(){function c(b){window.setTimeout(function(){var a=document.createElement("script");a.src=b;document.getElementById("xjsd").appendChild(a)},0)}google.dljp=function(b,a){google.xjsu=b;c(a)};google.dlj=c;}).call(this);(function(){window.google.xjsrm=[];})();if(google.y)google.y.first=[];if(!google.xjs){window._=window._||{};window._DumpException=window._._DumpException=function(e){throw e};if(google.timers&&google.timers.load.t){google.timers.load.t.xjsls=new Date().getTime();}google.dljp('/xjs/_/js/k\x3dxjs.ntp.en_US.FA_vN017Rto.O/m\x3dsx,jsa,ntp,d,csi/am\x3dBGg/rt\x3dj/d\x3d1/t\x3dzcms/rs\x3dACT90oH9nFbyjTsBefBncZNhBHui7Tkmvw','/xjs/_/js/k\x3dxjs.ntp.en_US.FA_vN017Rto.O/m\x3dsx,jsa,ntp,d,csi/am\x3dBGg/rt\x3dj/d\x3d1/t\x3dzcms/rs\x3dACT90oH9nFbyjTsBefBncZNhBHui7Tkmvw');google.xjs=1;}
 ..........

In a huge line.

What are the reasons? Is the gain in compression considerable? These codes are handmade by some extraterrestrial :)

  • 1

    possible duplicate here and here

  • Reducing JS file size is one of the reasons.

  • 1

    beauty, I think I understand why the name min.js :) So obvious and I never thought about it!

  • 4

    Generally, codes are not written that way. The original code goes through a process to make the code "ugly" (uglify) where there is the exchange of variable and function names by simpler and smaller names, removal of spaces, tabulations and line breaks. All this with the intention of decreasing the size of the code, making it lighter and difficult to understand and modify in any way, either for improvement or by searching for faults or something like.

  • @Hamurabiaraujo very good this explanation, that’s what I wanted to know when asking if "they are handmade by some alien"

  • @Leocaracciolo, I’m glad I helped you understand ;)

Show 1 more comment

1 answer

4


People think that so no one will understand the wonderful code she wrote, which is still true, makes it a little difficult. In general, people who do this for this purpose usually don’t write such good code. But it usually works because it will only try to copy who is very bad to understand a code overshadowed. Who is good does not waste time.

Some even think that will make their software safer. If so, it is a big mistake. Security cannot be used in this type of deception. Even an executable does not give security, imagine a source code, security coming from correct techniques.

Other than that it’s just reducing the load time of the script. If done well it makes a big gain.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.