Results 1 to 4 of 4

Thread: compress js

  1. #1
    Join Date
    Oct 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default compress js

    Hello,...
    I can't find how people make js,file in to small script.
    I have problem with big js,file,..because is to long for my HTML,and if I put few more,it make block for my HTML.
    Someone can help me explain what need to do for make small script js.file.
    For exaple like that:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

    Thanks.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Are you talking about minification? Where all white space / new lines are removed to compress the script and therefore file size?

    If so, do a search for "minify JS" and you'll find lots of online tools to do the job.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Feb 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm trying to minify js to reduce file size but after minifying I find that my site doesn't run properly. Does this happen to anyone else?
    Last edited by jscheuer1; 04-28-2016 at 03:00 AM. Reason: excessive quoting

  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

    Yes. In order to minify, depending upon the method used, the script code must increasingly adhere to standards, otherwise, conventions that allow for omissions at the end of lines will no longer be understood, and/or comments (if not stripped) can become problematical. For example, one can go:

    Code:
    var bob = "you're uncle"
    var ted = "alice"
    But without proper strict terminus, that cannot become:

    Code:
    var bob = "you're uncle"var ted = "alice"
    But if originally it was strict:

    Code:
    var bob = "you're uncle";
    var ted = "alice";
    It then can become:

    Code:
    var bob = "you're uncle";var ted = "alice";
    There are so many conventions like these that are loosely OK with line breaks, that will break a script if those line breaks are removed without adding strict notations of one sort or another that - well I think you get the idea.

    Basically strict javascript code is much more easily/successfully compressed than more loose/haphazardly written code.

    jslint is a good if sometimes frustrating tool to use to ready your javascript code for successful compression:

    http://www.jslint.com

    Even so (making the code compliant with such a tool), some certain techniques can still cause problems once code is compressed. For those, individual investigation is required.

    That said, javascript is ordinarily not all that big. You will have far greater savings in most cases via compressing the images a page uses.
    - John
    ________________________

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

Similar Threads

  1. Is it possible to compress an external hard Drive?
    By newguyj in forum Computer hardware and software
    Replies: 1
    Last Post: 03-30-2010, 12:15 PM
  2. Replies: 4
    Last Post: 07-30-2008, 11:18 PM
  3. PNG files re compress?
    By KB1 in forum Graphics
    Replies: 5
    Last Post: 09-13-2006, 12:17 PM
  4. How do i Compress a music file?
    By pbnationfreak in forum Other
    Replies: 1
    Last Post: 07-09-2005, 06:06 AM

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
  •