By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,795 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,795 IT Pros & Developers. It's quick & easy.

Browser script loading method

P: n/a
Hello,
I have a couple of questions regarding the loading of .js files for
the browser and would like anyone to point me wher to find the answer
(or if you know the answer and tell me will do just fine ;) )
- If I have several pages all using 'somejs.js' file this file is
shared on disk and is downloaded only once... but how about in memory,
is it also shared and just loaded once?

-Also, when are the .js files unloaded from memory?

-Can I unload at any given time a .js file from memory?

Thanks in advance

Feb 10 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
er************@gmail.com said the following on 2/10/2007 10:07 AM:
Hello,
I have a couple of questions regarding the loading of .js files for
the browser and would like anyone to point me wher to find the answer
(or if you know the answer and tell me will do just fine ;) )
- If I have several pages all using 'somejs.js' file this file is
shared on disk and is downloaded only once... but how about in memory,
is it also shared and just loaded once?
Typically, yes. But it depends on user cache settings and cache headers
sent with the file.
-Also, when are the .js files unloaded from memory?
When the page is unloaded.
-Can I unload at any given time a .js file from memory?
Not easily.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 10 '07 #2

P: n/a
<er************@gmail.comwrote:
I have a couple of questions regarding the loading of .js files
for the browser and would like anyone to point me wher to find
the answer (or if you know the answer and tell me will do just
fine ;) ) - If I have several pages all using 'somejs.js' file
this file is shared on disk
There is not much sense in "shared on disk" here. There is no necessary
relationship between a web server's responses to requests and the file
structure on the machine that is running it.
and is downloaded only once...
Presumably that it once per browser connection? However, each page that
references an external JS resource may request that resource anew form
the server. If they don't do so then the implication is that the JS is
cached on the client (which is mostly what would be expected) and
requests are being served from the browser's disc cache
but how about in memory,
is it also shared and just loaded once?
Javascript files are source code, which is used to define an executable
structure. A browser receiving a listing of javascript source code from a
server may store that in its disk cache for use with later requests
(possibly in later sessions), it may also elect to keep the source code
in memory for the current session in anticipation of further requests for
the same source.

For any given HTML page loaded into a browser a SCRIPT element's
reference to an external JS resource will necessitate the fetching of the
source code so that it can be processed into an executable for that
particular page. That source code may be fetched from the browser's
memory, the browser's disk cache, or the network (where it may be found
on an intermediate HTTP cache, or retrieved from the original server).

The executable structures created from the source code belong to the
individual page's representation in the browser. They cannot be shared
between pages displayed in the same browser (frameset frames or different
tabs) because they have a particular scope structure that relates to the
individual page. However, some browsers cache the page's representation,
so if you leave a page and then use the 'back' button to return to it
that representation can be re-used instead of needing to be re-built from
the original (HTML/CSS/JS) source code.
-Also, when are the .js files unloaded from memory?
The unloading of the javascript source files from memory (if they were
stored there more than fleetingly in the first place) is something that
can be left to the browser. The unloading of the executable structures
created from javascript source should follow the destruction of the
browser's representation of the page, which may follow the user's leaving
the page, or may be delayed until the browser is closed down.
-Can I unload at any given time a .js file from memory?
That is not under your control. You may influence the browser's (and the
network's) caching behaviour with appropriate HTTP headers. For example,
if an HTTP header states that a resource will expire in 10 minutes a
client may see no need to keep it in its cache (memory or disk) beyond
that point, as it should not re-use an expired resource.

The executable structures in association with a particular page's
reprehension are subject to javascript's normal garbage collection. If
you remove all references to the referenceable aspects of those
structures from the reprehension then the structures become available for
garbage collection and should be removed from memory at some subsequent
point.

Richard.

Feb 10 '07 #3

P: n/a
On Feb 10, 4:07 pm, ernesto.tej...@gmail.com wrote:
Hello,
I have a couple of questions regarding the loading of .js files for
the browser and would like anyone to point me wher to find the answer
(or if you know the answer and tell me will do just fine ;) )
- If I have several pages all using 'somejs.js' file this file is
shared on disk and is downloaded only once... but how about in memory,
is it also shared and just loaded once?

-Also, when are the .js files unloaded from memory?

-Can I unload at any given time a .js file from memory?
The replies you got already are very helpful, maybe I can bring my two
cents in making one detail more precise. When the client's browser
"loads" a javascript, it really includes it into the javascript
context of the web page. So, two instances of the same whateverjs.js
loaded by two different pages live independent lives, for instance
their respective global variables will assume independent values. Be
it in javascript or whatever interpreted language with a context that
I know, you can't extract one component which is making part of a
context from that context without deleting that context.

Emmanuel

Feb 10 '07 #4

P: n/a
On Feb 10, 4:39 pm, "Emmanuel" <satim...@gmail.comwrote:
On Feb 10, 4:07 pm, ernesto.tej...@gmail.com wrote:
Hello,
I have a couple of questions regarding the loading of .js files for
the browser and would like anyone to point me wher to find the answer
(or if you know the answer and tell me will do just fine ;) )
- If I have several pages all using 'somejs.js' file this file is
shared on disk and is downloaded only once... but how about in memory,
is it also shared and just loaded once?
-Also, when are the .js files unloaded from memory?
-Can I unload at any given time a .js file from memory?

The replies you got already are very helpful, maybe I can bring my two
cents in making one detail more precise. When the client's browser
"loads" a javascript, it really includes it into the javascript
context of the web page. So, two instances of the same whateverjs.js
loaded by two different pages live independent lives, for instance
their respective global variables will assume independent values. Be
it in javascript or whatever interpreted language with a context that
I know, you can't extract one component which is making part of a
context from that context without deleting that context.

Emmanuel
Thanks a lot guys that was the kind of answer I needed... could any of
you point me to where I can learn more?.. Books, links or online
articles.

Thanks once more!!

Feb 12 '07 #5

P: n/a
er************@gmail.com said the following on 2/12/2007 3:34 AM:

<snip>
Thanks a lot guys that was the kind of answer I needed... could any of
you point me to where I can learn more?.. Books, links or online
articles.
You will not find - bar none - a better JS resource than the one you are
posting in now - comp.lang.javascript and the FAQ for this group. There
simply doesn't exist a better resource.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 12 '07 #6

P: n/a
On Feb 12, 12:34 am, ernesto.tej...@gmail.com wrote:
Thanks a lot guys that was the kind of answer I needed... could any of
you point me to where I can learn more?.. Books, links or online
articles.
I highly recommend http://javascript.crockford.com

--
Isaac Z. Schlueter
http://isaacschlueter.com

Feb 13 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.