Results 1 to 4 of 4

Thread: Javascript Compression with PHP

  1. #1
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript Compression with PHP

    Dear JS Enthusiasts,

    What is the best way to pack a JS file as much as possible using PHP?

    Links would be appreciated.

    Thanks

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    To "pack a JS" file? What exactly do you mean by that?
    - Mike

  3. #3
    Join Date
    Oct 2006
    Location
    미네소타, 미국
    Posts
    158
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    the only way i could think of is to take out all unneccessary returns
    The only person I think is cool is -==INSERT YOUR NAME HERE==-

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Do you mean pack (compress its size)? Do you mean using PHP to do this or do you mean so that it takes up less space as an include or whatever? Javascript can be made to take up less space if variable and function names are shortened and unnecessary line breaks and punctuation are removed. Code can often be reduced more by reusing code that appears more than once and using ? : tests instead of if else tests.

    It is usually not worth it to do this unless bandwidth is very low. The resulting file will be hard to read and edit.

    One good practice with javascript is to keep scripts external and link them to the various pages using them (if more than one) via an external script tag (instead of an include or any other method). That way each script only needs to be cached once.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •