Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. All code on one line?

All code on one line?

Scheduled Pinned Locked Moved JavaScript
javascriptperformancequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • realJSOPR Offline
    realJSOPR Offline
    realJSOP
    wrote on last edited by
    #1

    Why do so many people put all their javascript into just one line of code? Is there a noticeable speed increase? I also read that putting comments into your javascript slows it down. Is that really true?

    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
    -----
    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
    -----
    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

    N R 2 Replies Last reply
    0
    • realJSOPR realJSOP

      Why do so many people put all their javascript into just one line of code? Is there a noticeable speed increase? I also read that putting comments into your javascript slows it down. Is that really true?

      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
      -----
      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      A minimized javascript file does load faster because it has fewer characters to transmit across the wire. Also why comments are removed, the javascript engine ignores them anyway. That's why you typically see two javascript files, like script.js and script.debug.js. the latter of course being used for debugging situations were it has full comments and formatting for readbility.


      I know the language. I've read a book. - _Madmatt

      realJSOPR 1 Reply Last reply
      0
      • N Not Active

        A minimized javascript file does load faster because it has fewer characters to transmit across the wire. Also why comments are removed, the javascript engine ignores them anyway. That's why you typically see two javascript files, like script.js and script.debug.js. the latter of course being used for debugging situations were it has full comments and formatting for readbility.


        I know the language. I've read a book. - _Madmatt

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        Unfortunately, the shadowbox source code does not include a "debug" file. They also use single-character variable names. It's virtually impossible to figure out what's being done and what it's doing it to.

        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
        -----
        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

        N 1 Reply Last reply
        0
        • realJSOPR realJSOP

          Unfortunately, the shadowbox source code does not include a "debug" file. They also use single-character variable names. It's virtually impossible to figure out what's being done and what it's doing it to.

          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
          -----
          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          A form of obfuscation :-D :-D


          I know the language. I've read a book. - _Madmatt

          1 Reply Last reply
          0
          • realJSOPR realJSOP

            Why do so many people put all their javascript into just one line of code? Is there a noticeable speed increase? I also read that putting comments into your javascript slows it down. Is that really true?

            ".45 ACP - because shooting twice is just silly" - JSOP, 2010
            -----
            You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

            R Offline
            R Offline
            RakeshMeena
            wrote on last edited by
            #5

            My answer is yes to all your questions. Removing unnecessary characters from javascript is known as minification and it does improve performance (I myself noticed this in one of my projects). Hence by the same logic removing comments will also improve performance. Also this is one of the suggest best-practices by Yahoo.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups