Dynamic Script Insertion & caching (Randy?)

P

Peter Michaux

Randy, have you done any work on an article summarizing the script
insertion results? Just curious and I'm interested to ready your
interpretation and how you use it.
[snip]

I haven't had time yet to be honest, when I do you will be one of the
first to know about it.

Script insertion must always be synchronous, yes? That is the browser
comes to a screeching halt until the server response. This would make
XHR suitable in some places where script insertion is not.

Do you ever insert script elements that have src attributes like
"perlScript.pl" to get dynamically created JavaScript. In particular
I'm thinking of getting JSON data specific to a particular user with a
session cookie to be sent with the browser's request for this inserted
script.

I certainly think this dynamic script insertion should be a better
known option along with XHR. It gets a mention at the end of the
"Scripting HTTP" chapter of Flanagan's fifth edition but I didn't take
it seriously because he doesn't push the pros much. He only mentions
it as something that can be done to get around IE browsers with
ActiveX turned off and so no XHR option.

Thanks,
Peter
 
R

Randy Webb

Peter Michaux said the following on 2/4/2007 1:34 AM:
<snip about dynamic script insertion and ensuring the browser doesn't
just use the cached version the second time the same script is
inserted in a page>


A URL query string time stamp? While we are at it that deserves a test
too.

I don't think testing a URL query string time stamp is worthwhile
though. If you find a browser that won't retrieve it from the server and
gets it from the cache instead then you have a severely broken browser.
If we are going to go to the trouble of firing up 40+ browsers can we
change the tests? Instead of using alerts for each we could have the
HTML to be inserted in the results table appear in a textarea element.
I think that is supported in browsers as far back as...well...a long
time ago.

I have a project at work that is limiting my time right now but changing
the test to insert the results in a textarea would be trivially simple
to do.
 
R

Randy Webb

VK said the following on 2/4/2007 9:32 AM:
So you know a way to be informed if file on server is changed without
contacting the server?

I said nothing about that. You said the "only alternative" is to set a
timed updated and that doesn't even come *close* to solving the OP's
question. You should try re-reading it several times until you
potentially understand the question before trying to reply to it.

I do perfectly - but you still trying to mix two flavors in one bottle
(which is your brand style IMO): i) do I have new data to load? ii) if
yes then how to enforce new data to load - instead of occasional cache
reusing. I'm answering on the first one so far.

I have a hard time believing that you have the first clue about what you
are trying to answer on. The question was how to *only* get the file
from the server *if it has changed*.
 
R

Randy Webb

Peter Michaux said the following on 2/5/2007 12:19 AM:
Randy, have you done any work on an article summarizing the script
insertion results? Just curious and I'm interested to ready your
interpretation and how you use it.
[snip]

I haven't had time yet to be honest, when I do you will be one of the
first to know about it.

Script insertion must always be synchronous, yes?

Never tested it but my first thought would have to be yes. But, creating
a dummy .js file of about 100K to test it with would settle it :)
That is the browser comes to a screeching halt until the server
response. This would make XHR suitable in some places where script
insertion is not.

Very valid point.
Do you ever insert script elements that have src attributes like
"perlScript.pl" to get dynamically created JavaScript. In particular
I'm thinking of getting JSON data specific to a particular user with a
session cookie to be sent with the browser's request for this inserted
script.

myJSFile.php but never perlScript.pl :)

The browser doesn't care what you name it. I have some pages that send a
parameter with it and returns table data based on that parameter.
I certainly think this dynamic script insertion should be a better
known option along with XHR.

I'm trying, I'm trying :)

It has its benefits and drawbacks to both.
It gets a mention at the end of the "Scripting HTTP" chapter of Flanagan's
fifth edition but I didn't take it seriously because he doesn't push the
pros much. He only mentions it as something that can be done to get around
IE browsers with ActiveX turned off and so no XHR option.

That is part of what got me started on it to begin with was the ActiveX
issue along with absent XHR support at the time.
 
P

Peter Michaux

Peter Michaux said the following on 2/4/2007 1:34 AM:

I don't think testing a URL query string time stamp is worthwhile
though. If you find a browser that won't retrieve it from the server and
gets it from the cache instead then you have a severely broken browser.
From what I've heard, that "broken" browser would be following the
HTTP specs properly. I haven't looked in the specs.

Peter
 
P

Peter Michaux

When I insert two scripts dynamically, Safari doesn't respect the
insertion order. If the first script inserted is large then the second
shorter script will load and run earlier.

<URL:http://peter.michaux.ca/temp/scriptInsertLoadOrder/test.html>

My versions of IE6 and Opera9 do respect insertion order. IE7 does
not.

This may have more to do with how the browser is configured: number of
simultaneous connections etc. I don't know but I can't control those
aspects of a client anyway.

Randy, do you ever implement callbacks for sequentially loading files?
Something like polling the window object for a particular property
that will exist when the first script loads. Then load the second one?
I'm not going to do this but I'm curious if you do.

Peter
 
R

Randy Webb

Peter Michaux said the following on 2/11/2007 2:39 PM:
My versions of IE6 and Opera9 do respect insertion order. IE7 does
not.

My IE7 respected the insertion order. But, it took it almost 3 minutes
to display the results. For some reason, it didn't like that string
concatenation at all.
This may have more to do with how the browser is configured: number of
simultaneous connections etc. I don't know but I can't control those
aspects of a client anyway.
Randy, do you ever implement callbacks for sequentially loading files?

No as I typically load one at a time. Never had an issue with timing
with them either.
Something like polling the window object for a particular property
that will exist when the first script loads. Then load the second one?
I'm not going to do this but I'm curious if you do.

No, never had a reason to even try.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top