[Javascript] Javascript include problem?

Mike Dougherty mdougherty at pbp.com
Sat Oct 2 14:55:35 CDT 2010


On Sat, Oct 2, 2010 at 11:45 AM, Jason Pruim <lists at pruimphotography.com>wrote:

> I'll start changing all my stuff to use the external script commands then
> :) But with the caching... Would it store all the variables as well? What
> the whole page is doing is simply displaying a google map of a point that is
> retrieved from my database... So caching isn't necessarily what I'm looking
> for... Unless it would refresh the variable with the ID number but store the
> rest of the script...
>
> You also said it worked? What browser are you using and what page are you
> visiting? :) I'm still fighting with it hehehe :)
>
>
"worked" is open to interpretation I guess - I didn't see any errors or
particular ugliness.  I have no idea how much of what I'm not seeing is
broken vs. not-yet-implemented.  I guess I gave large benefit of the doubt
:)

when you ask "would it store my variables" - are you sure your declarations
are 'variable' if they're hardcoded in a file now?

Typically you would have let's call it 8-10k worth of function definitions
and other program code to make your page work.  If you have less than 1k
worth of data that changes frequently compared to the program code, for
example: weather details, then consider:  Put the program code in one script
file and the data in another file.  Reference both in your markup.  The
browser will request the program code effectively, "Hey, has the file I
downloaded last week with X timestamp+bytecount still fresh?"  If the server
says, "Yup, that's what I'd serve up: use it" then you save the time it
takes to download 8-10k worth of code the browser already has.  Then the
browser says, "What about this data file I have from 5 days ago?"  and the
server responds, "No I update this file hourly, here's the 1k of new data"
Instead of downloading markup(4k)+program(10k)+data(1k)=15k, you download
markup(4k)+program(cached)+data(1k)=5k and your page is ready 66% quicker.

If it sounds like I'm just being a kook about a few bytes, download the
YSlow extension to Firebug (in Firefox) and examine the page weights of
"unprimed cache" vs "primed cache"  and qualitatively feel the difference
between a content-rich page like cnn.com on first-download and subsequent
requests.  (1141.4K vs 109.4K)

The takeaway (if there is one) is that you build for performance from day 1
- high performance is not something you can add-on at the end of a project
when you find that it's too slow/clunky for anyone to tolerate.  I would
also preemptively counter the "Oh this is just a small project I'm doing for
fun, so it doesn't really matter"  with the suggestion that small/fun
projects are how you learn to do things the proper way - so when you get the
large project you already have good habits/skills.  Then of course the
project manager/boss will push you to cut corners for the sake of time/money
budgets  :)


More information about the Javascript mailing list