Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 53
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    how to hide javascript code in page source?

    So i've tried to use online tools such as these:
    http://ostermiller.org/calc/encode.html
    http://dean.edwards.name/packer/

    But they are not effective in truly hiding the javascript.

    Is this possible?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,203
    Thanks
    23
    Thanked 605 Times in 604 Posts
    Why do you want to hide the code? Could what your doing be done server side? What code is it your trying to conceal?
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by otherwhirl View Post
    So i've tried to use online tools such as these:
    http://ostermiller.org/calc/encode.html
    http://dean.edwards.name/packer/

    But they are not effective in truly hiding the javascript.

    Is this possible?
    No. thats the best you can do. You can pack, obfuscate etc.. but in the end the browser still has to be able to read it, so a human can too,fairly easily. Search the forums, youll find several long posts talking all about the subject

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    And of course, we always ask the question: What is it you are doing that you think is *worth* hiding? If (example only!) Google doesn't/can't hide their JS and all that it does (e.g., Google Maps API, and so many more), how is your code so much more sophisticated than theirs that it is more important to hide it?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Attempts to hide JavaScript are usually a good indicator of the quality of the JavaScript - only the most badly written JavaScript that no one would ever want to steal ever uses an approach that attempts to hid the code.Presumably the real reason people have for wanting to hide their JavaScript code is that they are trying to conceal how badly written it is.

    A better alternative would be to learn how to write JavaScript properly so that you don't need to be so ashamed of the quality of the code that you need to try to hide it.


    Dean Edward's packer was used to reduce the size of JavaScript to make it faster to download back in the days before browsers supported built in compression in file downloads. It is no longer used because the the slightly faster download when you use it compared to the download time when you use the built in compression with the original source is more than outweighed by the slower execution time of the packed version compared to the original. It is now faster to download and riun the original than it is to use packer. Packer was never intended to "hide" the source.
    Last edited by felgall; 08-06-2013 at 10:24 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,346
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by felgall View Post
    Dean Edward's packer was used to reduce the size of JavaScript to make it faster to download back in the days before browsers supported built in compression in file downloads. It is no longer used because the the slightly faster download when you use it compared to the download time when you use the built in compression with the original source is more than outweighed by the slower execution time of the packed version compared to the original.
    just to be clear, the actual packed code runs just as fast as the same but unpacked code once unpacked. the unpacking is quick, thanks to a speedy unpack routine i still marvel at in my spare time... for example, the popular json2.js lib unpacks in 0.32ms on my old core3 laptop, not exactly a deal-breaker. it's not even noticeable outside a repetitive testing environment, even if it took 50X longer than it actually does.

    a lot of environments don't support gZip, and many configs (like iis's default) disable it for dynamic pages, so there still is a place for packer out there, especially when bandwidth is low. further, it can same you money depending on how your web host bills; many still bill bandwidth as calculated by static file size * quantity, which doesn't count gzip's savings. in that case, packing your json data and common scripts can increase the number of people your site can reach per $.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,346
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by Old Pedant View Post
    If (example only!) Google doesn't/can't hide their JS and all that it does (e.g., Google Maps API, and so many more),
    view source on just about any google page, be it news, search, or gmail and tell me honestly that the javascript is usable. you are smart to mention maps, because it's the only one i know that doesn't use renaming Closure and other tricks to make it small and stealthy.

    that said, it's usually bad code anyway, laden with stuff like href="javascript:void(0)", so don't steal it.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #8
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is it possible to hide the javascript code from the html of a webpage, when the source code is viewed through the browsers View Source feature?

  • #9
    New Coder
    Join Date
    Jun 2012
    Posts
    80
    Thanks
    0
    Thanked 18 Times in 18 Posts
    You can't hide any thing on client side code, if you want to hide them to it on server side.

  • Users who have thanked Richter for this post:

    otherwhirl (08-08-2013)

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by rnd me View Post
    just to be clear, the actual packed code runs just as fast as the same but unpacked code once unpacked. the unpacking is quick, thanks to a speedy unpack routine i still marvel at in my spare time... for example, the popular json2.js lib unpacks in 0.32ms on my old core3 laptop, not exactly a deal-breaker. it's not even noticeable outside a repetitive testing environment, even if it took 50X longer than it actually does.
    JQuery abandoned using packer because a compressed minimised version downloads and runs faster than the packer version even though it is a slightly larger download.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #11
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,346
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by felgall View Post
    JQuery abandoned using packer because a compressed minimised version downloads and runs faster than the packer version even though it is a slightly larger download.
    actually jQuery+base62+gZip is a larger download than jQuery+gZip, run some tests yourself if you don't believe me. if you want a quick view of the phenomenon, try loading the js parser Demo at http://danml.com/slim/, and choosing "Run All" from the tools menu.

    what i see is this:
    Code:
    name                 	time	bytes	saved	 ratio	gzipd
    Packer                 	26	7210	3034	0.704	2249
    Packer (w/base62)    	38	5051	5193	0.493	2588
    you can see that while the "bytes" count is lower, as expected, the size after gZip (deflate) is slightly higher for the base62 version, probably owing to the larger vocabulary needed by deflate. but without gZip, the 'bytes' col is what counts. it matters as well if you have to store the code client-side, where space is at a premium and in which case gZip does nothing to help.

    i think it would be nice if a server could serve the gZip one to clients that support it and the packed one to client that need plain encoding, or a queryString flag to toggle between the two, kinda like the difference between http://danml.com/js/json2.js and http://danml.com/js/?json2...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #12
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Is there any particular reason why you would assume I am "ashamed" as you put it? (LOL!)

    fdirst of all I did not create the javascript myself (furthermore I could care less if the code met your 'standards' or anybody elses...)

    This thread was created to find an ANSWER to my question, not to be accused and ridiculed of things that aren't even true.

    If it what I have asked is not possible then a simple yes or no would have sufficed.

    Quote Originally Posted by felgall View Post
    Attempts to hide JavaScript are usually a good indicator of the quality of the JavaScript - only the most badly written JavaScript that no one would ever want to steal ever uses an approach that attempts to hid the code.Presumably the real reason people have for wanting to hide their JavaScript code is that they are trying to conceal how badly written it is.

    A better alternative would be to learn how to write JavaScript properly so that you don't need to be so ashamed of the quality of the code that you need to try to hide it.


    Dean Edward's packer was used to reduce the size of JavaScript to make it faster to download back in the days before browsers supported built in compression in file downloads. It is no longer used because the the slightly faster download when you use it compared to the download time when you use the built in compression with the original source is more than outweighed by the slower execution time of the packed version compared to the original. It is now faster to download and riun the original than it is to use packer. Packer was never intended to "hide" the source.

  • #13
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,015
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Your question was "how to hide javascript code in page source?" This is a very old question which has been answered many, many times before. Including in a sticky. http://www.codingforums.com/javascript-programming/34358-javascript-frequently-asked-questions-post252783.html

    The answer is "THAT IS NOT POSSIBLE". OK? It is also reasonable to ask why you want to do this in any case.
    Last edited by Philip M; 08-08-2013 at 11:27 AM. Reason: typo

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #14
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    My purposes have to do with marketing reasons .
    It has ZERO to do with what Google thinks...

    Quote Originally Posted by Old Pedant View Post
    And of course, we always ask the question: What is it you are doing that you think is *worth* hiding? If (example only!) Google doesn't/can't hide their JS and all that it does (e.g., Google Maps API, and so many more), how is your code so much more sophisticated than theirs that it is more important to hide it?

  • #15
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by rnd me View Post
    actually jQuery+base62+gZip is a larger download than jQuery+gZip,
    I never commented on which was larger. A larger download can run faster if the smaller one has to "unpack" itself first.

    Anyway, I only mentioned that in order to point out that "packer" was not created for the purpose of hiding JavaScript - which of course is impossible.
    Last edited by felgall; 08-08-2013 at 08:32 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  
    Page 1 of 4 123 ... LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •