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.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts

    HTTP requests versus filesize

    I hear a lot about trying to reduce the number of HTTP requests that a web page makes, but I also hear about reducing the filesize of scripts and stylesheets to reduce page loading times.

    Which is better; having a selection of different scripts and stylesheets and including them based on which is being used for that particular page (reducing the amount of bandwidth) or combining them all into one file and including that on every page (reducing the number of HTTP requests).

    Is it any different when I am using iframes? I have one page that includes a few different frames. Between them, the frames reference about five different scripts (between 0 and 3 scripts per frame). Again, is it better to have a universal script file, or separate stylesheets referenced by the frames which need them?
    Last edited by name _F1; 01-11-2008 at 12:53 PM.

  • #2
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    You'll have to make a balanced choice. I read an article once describing the amount of time the browser took making HTTP requests versus actually downloading the file on a fast connection--and the request was longer

  • #3
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Personally, I've found it better to combine multiple scripts and CSS files—where appropriate—and use gzip on the server for compression.

  • #4
    New Coder
    Join Date
    Jun 2007
    Location
    Quebec, Canada
    Posts
    64
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Thanks for the thread, i had this in mind!

    I have to add a question, would you guys rather include the 2kb menu into each 15kb page, or rather have every page ~17kb?

    I am using a 2kb menu as an example, but i am including kinda large lists (60-70kb, and i am being careful on size).

    [ out of topic : i think iframes are really innapropriate uses as of 2008. Ever tried printing information included in an iframe? I did. Ever tried going back in the history while browsing a iframed website? I hope you never did. Considering there are better (maybe not easier) ways to achieve the same, i believe this task belongs to the developper. ]

    ~

  • #5
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Includes will theoretically slow the page down. But they're easier to maintain. I prefer to use them.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Whether it will be faster to make requests for more files or for fewer bigger files will depend on:

    A. How much the extra files are reused by additional web pages so as to be able to reuse them from the cache rather thatn reading the same file multiple times (depends on how many of your pages a given visitor visits).

    B. Depends on the connection speed of a given visitor - those on a faster connection will get a faster download from fewer bigger files while those on slower connections may get a faster download from more smaller files.

    You have to find the appropriate balance to suit the connection speed and viewing habits of your typical visitor.
    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.

  • #7
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Do includes make HTTP requests? I asked my mate about it and he said they were fileserver movements rather than requests. I always took his word.

  • #8
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by CyanLight View Post
    Do includes make HTTP requests? I asked my mate about it and he said they were fileserver movements rather than requests. I always took his word.
    Depends, server side includes are done on the server and as such, don't involve any extra requests. But client side includes like referencing stylesheets and scripts, do require additional requests.

    Keep in mind though that generally speaking things like your stylesheet will get cached by the client's browser after the first page view and won't be re-requested on other pages that use the same stylesheet.
    OracleGuy


  •  

    Posting Permissions

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