SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Corner seat
    Posts
    1,069
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Compiled JavaScript?

    Can we compile JavaScript? We can't, right? Well, here's my problem. A page in my site uses JavaScript rather extensively. I was looking at the code and realized that the page loads number of js files and all these files have a lot of comments written. Commenting is an important part of coding, but almost no user is interested in reading these comments. So ... what I'm wondering about is ... is there some way to get rid of these comments when these JavaScript are loaded from the server? It's not compiling JavaScript and we can't do that, but at least, isn't there a way to clean up comments when clients load JavaScript so that scripts get loaded much faster?

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    There are applications around that will strip your files of comments, newlines, tabs, etc. If you have that much JS code going around it may save you some bytes. I recommend keeping a "safe" copy with all the comments around though, then running one of those programs before you release your pages to production.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You didn't mention what server-side languages you had access to, but here's one example of a program that strips JS commenting out when serving files: http://www.anvilon.com/software/jsjam/ (Perl). I've seen others...vgarcia's approach seems more sensible, though...
    ::: certified wild guess :::

  4. #4
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Corner seat
    Posts
    1,069
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You didn't mention what server-side languages you had access to, but here's one example of a program that strips JS commenting out when serving files: http://www.anvilon.com/software/jsjam/ (Perl). I've seen others...vgarcia's approach seems more sensible, though...
    Actually, this is the type of approach I'd like to take. vgarcia's approach seems to work, but one thing I don't like is that apparently I need to run this strip-JavaScript-script every time I deploy a new version of my site. Oh, by the way, I'm using JSP(Java), so it would be great if there is strip-JavaScript-script written in JSP or Java.

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've written one in PHP myself - not that hard. Just some regular expression based find-replace type stuff. I don't know Java but I'm sure it isn't hard.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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