Every byte is sacred, every byte is good.

Nao

  • Dadman with a boy
  • Posts: 16,079
Every byte is sacred, every byte is good.
« on February 10th, 2013, 11:20 AM »
And here's a topic about my all-time biggest obsession: bytesize reduction through gzip optimization...

Every byte saved after gzipping is a byte that doesn't have to go through the Internet pipes. Meaning it saves energy. Not much, but do you want your website to load fast? Yes? Then every byte saved is a step closer to that reality.

I'll post here any remarks I have regarding my work on this. Or any questions when the byte crunching comes at a possible price.
Here's the first of these cases I'd like to discuss. :edit: Actually, see last paragraph, already solved the first problem by myself, the second one really isn't that important, basically: you may skip this post entirely unless you're interested in exploring the mad psyche of yours truly. :geek:

I've rewritten the Thought class to move all of its text strings to the script.js file. First thing: sSubmit was totally redundant -- never used in the class, I forgot to remove the declaration after replacing it with we_submit. So that one's a freebie -- about 10 bytes saved!

Now, I moved sNoText, sEdit, sReply and sLabelThought to the script file. Since there's only one variable left (the privacy array), I also removed the aPrivacy name, and left it to just the array declaration. That saves a total of about *70 bytes* per gzipped file (80 counting the sSubmit thing). That's a *very* nice score. I'm also
Let's look at script.js now... After adding our text strings (and reordering them for good measure to see if I could save more bytes), I managed to reduce the overhead to about *30 bytes*.

First dilemma: is it worth adding 30 bytes of (a single download) to ALL users (including guests), to save 70 bytes (PER PAGE) for logged in users?

Second dilemma: I added an additional trick to save *25 bytes* per page load for *logged in users* who have *not yet set a thought* (that would represent, I think, a majority of them.) Instead of showing "Click here to set your first thought", I'm showing nothing, and then script.js fills in the text by itself. This adds approximately 8 bytes of overhead to the script file. Is it worth adding a single download of 8 bytes for everyone (including guests) to save 25 bytes per page for a majority of members?

I think that's all for now...
The things to keep in mind are that, (1) all of these strings are located at the bottom of the page, so hypothetically they're not supposed to slow down the page load, but in reality none of the browsers that I know show a 'partial' page when they've received part of the gzip for it, so essentially this is the same as if the text was at the beginning of the page. (2) adding 40 bytes represents about 0.5% of the total script file size. Removing 70 bytes off the homepage accounts for 0.8% of it.

Also, I should use the opportunity to simply suggest adding support for *guest* and *member* JS files... That would solve dilemma number 1 immediately. And a good deal of others. It also technically increases the number of JS files by 2, but it's *nothing* compared to the CSS cache, obviously. Not only that, but I can entirely remove the Thought object for guest files...!
Oh well, I think I'm going to do that... Perhaps I could use some help in finding the equivalent of a @if_guest and @if_member for the JavaScript files..? Woohoo, gonna have some fun... :lol:

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Every byte is sacred, every byte is good.
« Reply #1, on February 10th, 2013, 05:12 PM »
Quote
First dilemma: is it worth adding 30 bytes of (a single download) to ALL users (including guests), to save 70 bytes (PER PAGE) for logged in users?
Putting aside search engines (who shouldn't be requesting external files like JS), the reality is that for most sites, there are likely to be many more guests than regular users.

Right now, the stats are 12 Guests, 4 Users (2 Spiders) -> 10 regular guests to 4 users.

However, 30 bytes to a one-off download to save 70 bytes for registered users, this seems like a very worthwhile saving in total.
Quote
Second dilemma: I added an additional trick to save *25 bytes* per page load for *logged in users* who have *not yet set a thought* (that would represent, I think, a majority of them.) Instead of showing "Click here to set your first thought", I'm showing nothing, and then script.js fills in the text by itself. This adds approximately 8 bytes of overhead to the script file. Is it worth adding a single download of 8 bytes for everyone (including guests) to save 25 bytes per page for a majority of members?
8 bytes for everyone once? DO EEEET.
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial