doutan5844 2014-10-26 15:54
浏览 80
已采纳

混淆:JS保护

I've been writing lots of code for many years, but in the past it's never been required to be protected, mainly because the code was written for clients and not myself.

I have lots of JavaScript & jQuery code that I have written, my biggest issues is that I have Ajax requests as well, and these communicate with internal PHP files.

Here's a sample of code from Google:

function Yf(a, b, c) {
        c && (b = r(b, c));
        if (document.addEventListener) try {
                Zf(document, "DOMContentLoaded", b, a)
            } catch (d) {
                Zf(window, "load", b, a)
            } else if (!document.uniqueID && document.expando) var e = document.createElement("tempnode"),
                f = window.setInterval(function() {
                    try {
                        e.doScroll("left")
                    } catch (a) {
                        return
                    }
                    window.clearInterval(f);
                    f = e = null;
                    c && (b = r(b, c));
                    b()
                }, 50);
            else "readyState" in document ? f = window.setInterval(function() {
                    /loaded|complete/.test(document.readyState) && (window.clearInterval(f), f = null, c && (b = r(b, c)), b())
                },
                50) : Zf(window, "load", b, a)
    }

=====================================

Code comes from this url: http://www.google.com/inbox/assets/js/main.min.js

Online JavaScript beautifier: http://jsbeautifier.org/

Is this obfuscated or is it written this way from the beginning? (Sure, one can follow along and read this code and other lines, but there's no evidence of any Ajax requests that are communicating with an (or several) internal page files)

Similar question might have been posted previously, but bear with me.

  • 写回答

1条回答 默认 最新

  • duangu6431 2014-10-26 16:09
    关注

    Usually, no.

    All those single letter variables are often the result of running code through a JavaScript minifier.

    JavaScript code gets sent to the browser over HTTP, so it's practice to make the code as compact as possible to save on bandwidth (which, in Google's case, can be a lot). This involves the use of a minifier, which acts like a compiler of sorts that takes existing JS code and transforms it and optimizes it to be functionally identical, but in a much smaller size.

    For more detail you can see the Wikipedia page on minification, which states:

    Minification (also minimisation or minimization), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code without changing its functionality. These unnecessary characters usually include white space characters, new line characters, comments, and sometimes block delimiters, which are used to add readability to the code but are not required for it to execute.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?