Google Groups Home
Help | Sign in
JSAN.use() and x-browser caching strategies
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Rob Kinyon  
View profile
 More options Sep 9 2005, 9:50 pm
From: Rob Kinyon <rob.kin...@gmail.com>
Date: Fri, 9 Sep 2005 21:50:25 -0400
Local: Fri, Sep 9 2005 9:50 pm
Subject: JSAN.use() and x-browser caching strategies
First off, I want to apologize for any comments I have made in the
past that sound like I know what I'm talking about vis-a-vis this
topic. While I know JS as a language, I don't know JS as a technology
as well as I need to, especially when it comes to browser-dependent
behavior. In addition, if anyone wants to correct me in anything I
say, please do so without fear that you will hurt my feelings.

Second, this is a LONG email. Before responding, please take the time
to read it all. If you want to respond to one part, please consider
creating another thread (with a different subject) that refers back to
this one. The subject is how GoogleGroups threads responses.

Recently, I've been working with Casey West and Adam Kennedy on
getting JSAN.js to reduce the number of XMLHttpRequests it makes.
Currently, it uses XMLHttpRequest + eval() (hereafter known as the XHR
method) to do the load of a given library. Some browsers, such as IE,
will cache the results of an XMLHttpRequest if the right settings have
the right values. Other browsers, such as Firefox, seem to refuse to
do so, regardless of what's attempted. This means that a single
JSAN.use() statement may result in 3-10 XHRs per pageload, even if the
code in question has already been previously seen in a prior page.

This topic was brought up in the first days of this project, and
various strategies have been suggested and some have been implemented.
However, I cannot find a single document that discusses them, their
strengths and drawbacks, and what's needed to implement them from a
user's perspective. I'd like to remedy that. Hopefully, this thread
will get enough information in one place so that we, as a group, can
make up for the shortcomings in Javascript. (Who designs a dynamic
language in the modern era without making provision for libraries??
COBOL has libraries ... why doesn't Javascript?!?)

There are two caching levels, as I see it.
1) Page-level : this is where the same library is requested only once
per page load.
2) Session-level : this is where the same library is requested only
once per browser session. All session-level strategies are, by
definition, also page-level strategies.

The strategies, as I know them, consist of the following:
1) XHR - this is the strategy currently implemented in JSAN.js v0.10.
It depends completely on whether the browser caches XMLHttpRequests
for its session-level caching. It does provides for something similar
to Perl's %INC, page-level caching is there. This requires nothing
special on the server or client.

2) Serverside strategies - this is epitomized in Dave Rolsky's
JSAN::ServerSide, available on CPAN. Basically, the webserver will
modify the outgoing page so that all the dependencies are in the page
as <script> tags, in the right order. All modern browsers cache the
results of <script> tags, so this provides for session-level caching.
This requires mod_perl on the server.

3) Install-time concatenation - this is where the installer
(JSAN::Shell or JSAN::Shell2) would modify the library so that it
contained all of its dependencies within it. The user would then load
the library in a <script> tag, triggering the browser's session-level
caching. I'm not sure how this would play out, especially if a
dependency is updated or if a dependency is also loaded.

4) JS header files - this is a second file containing the dependencies
would be created, either manually or with some tool. JSAN.use() would
then be rewritten to use either DOM injection or document.write() to
add TWO <script> tags on the fly. The first would be the header (.jsh)
file and the second would be the code (.js) file. This similar in
concept to the bootstrap script that MochiKit uses. This requires
nothing from the user, but it does require some work on the part of
the developer. In addition, some scenarios still don't work, such as:
<script>
JSAN.use('Foo.Bar');
var x = new Foo.Bar();
</script>

If I missed anything, please add it.

I'm not looking for the "One True Way"(tm). Several of these
strategies can be used in tandem. What I am looking for is group
consensus on the "One True Way"(tm) for each of these strategies, and
also if the group feels that a strategy sucks too much, that it should
be dropped. I feel we need to bring the group's talents to bear on a
few good methods, so that we can speed adoption and get this monkey
off the project's back. The first question people ask me is "What's
performance like?" and I have to tell them "It can suck, depending on
the client." At that point, I lose them, and that's a "Bad Thing"(tm).

Thanks,
Rob


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
j...@ali.as  
View profile
 More options Sep 9 2005, 11:56 pm
From: j...@ali.as
Date: Sat, 10 Sep 2005 13:56:57 +1000
Local: Fri, Sep 9 2005 11:56 pm
Subject: Re: JSAN.use() and x-browser caching strategies
You can find a description of how the server side modes work in the wiki

http://master.openjsan.org/documentation/wiki/index.cgi?UseServer

Secondly, it's not likely you do concat at install time, rather you
would take a list of needed modules for a website and create a master
site.js for the whole site, perhaps with separate page-specific ones if
things get heavy.

Adam K


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Vilain  
View profile
 More options Sep 11 2005, 11:27 pm
From: Sam Vilain <s...@vilain.net>
Date: Mon, 12 Sep 2005 15:27:57 +1200
Local: Sun, Sep 11 2005 11:27 pm
Subject: Re: JSAN.use() and x-browser caching strategies

On Fri, 2005-09-09 at 21:50 -0400, Rob Kinyon wrote:
> <script>
> JSAN.use('Foo.Bar');
> var x = new Foo.Bar();
> </script>

This problem just goes away if you go asynchronous with includes; you
can just add <SCRIPT> tags to the header and be done with it;

It would look like:

  var x;
  JSAN.use("Foo.Bar", function(){
              x = new Foo.Bar();
           });

The idea is that once "Foo.Bar" is loaded, the closure fires.  Then it
is cached normally by browsers.

Sam.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google