>> Ajax.SingleUpdater - Fetches the URL once, then returns the same
>> content on
>> subsequent calls with the same URL.
> We already have that. Make a single Ajax.Request, then re-use the content.
Right. As I said, people can re-implement this each time, though I
think this is a drag and should be considered for inclusion in the
framework. Also, unless I'm missing something, since requests takes
time to complete and there may be multiple requests simultaneously,
any re-implementation must include a mechanism either for callbacks or
cached events once the initial request is completed. Therefore, for
the legions of people who are relatively new to JS and AJAX, trying to
use your framework, it may not be as trivial as you suggest.
Consider Exhibit A: my own ugly but functional solution, limited to my
specific problem domain and not reusable. (== bad code). I wrote it
to get around the fact that I can't get any caching to work, ever,
with Prototype. (see response further down for further info on this)
var dfs_lc=''; // languages cache
var dfs_l_w = new Array; // code queued for execution when language
content is loaded
function dfs_langs(n) {
if(dfs_lc=='in_progress') {
dfs_l_w.push('e(n).innerHTML=dfs_lc;');
}
else {
dfs_lc=1;
new Ajax.Request('/m_ajax/languages',
{method:'get',onComplete:function(tr)
{dfs_lc=tr.responseText;e(n).innerHTML=tr.responseText;for(i=0;i<dfs_l_w.length;i
++){eval(dfs_l_w[i])}}});
}
}
Do tell me if I'm going wrong somewhere and there's some sort of easy
way to implement the above.
If there's no easier way, I would still like to see a generic method
similar to this one included in Prototype, as this type of
functionality is going to become a common requirement as AJAX matures.
> > Ajax.CacheableUpdater - Respects standard HTTP 'Expires' / 'Pragma' headers
> > when deciding whether to re-issue an HTTP request or return the last content
> > fetched.
> We already have that. Use Ajax.Updater over GET and let the browser take
> care of the specifics of HTTP.
Sorry, this has not been my experience.
Consider the above function when called multiple times from a single
document. It works OK.
But if I replace the calls to that function with Ajax.Updater, the
same URL, and GET, it doesn't - the same URL is fetched many times.
The exact code in the document is as follows:
<script type="text/javascript">new Ajax.Updater('title[1][l]','/m_ajax/
languages',{method:'get'});</script>
Resulting headers below.
Response Headers
Transfer-Encoding chunked
Content-Type text/plain;charset=UTF-8
Cache-Control public, pre-check=604800, post-check=604800, max-
age=604800
Date Sat, 24 Mar 2007 09:49:03 GMT
Server Blah
Request Headers
Host 192.168.1.1:89
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3)
Gecko/20070309 Firefox/2.0.0.3
Accept text/javascript, text/html, application/xml, text/xml, */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-Requested-With XMLHttpRequest
X-Prototype-Version 1.5.0
Referer http://192.168.1.1:89/en/cms/articles_article/9
Pragma no-cache
Cache-Control no-cache
Four separate requests are issued.
If you are correct, there should only be one.
Maybe I'm missing something? I don't think so though: I use the same
cache control headers successfully to cache other elements (images,
javascript, css) that are loaded from the same server on the same page
view, and they are not re-requested by Firefox.
Finally, I would like to point out that the 'let the browser handle
it' approach, while OK if it works, does take some freedom/flexibility
away from the client-side coder - ie: the Prototype API user / coder -
and places it exclusively with the server-side programmer. In the
event that these two people are not one and the same, or that you
would like an easy client-side solution to override any potential HTTP
header complexities at the server side, adding such functionality
would still be useful.
- Walter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---