I've started writing a Javascript library for rapidly implementing / prototyping AJAX on a web page. Here is how it works:<p>When you click a link, the foreign web page is DIFFed with the current page with a server script and the script returns what has changed on the current page in the JSON format. For example,<p><pre><code>  [
    {
        "action" : "delete",
        "path" : "/p[1]"
    },
    {
        "action" : "modify",
        "path" : "/ul[1]/li[1]",
        "node" : {
            "innerHTML" : "modified 1st line",
            "attributes" : {
                "class" : "testClass"
            }
        }
    },
    {
        "action" : "insert",
        "parentPath" : "/ul[1]",
        "siblingPath" : "/li[3]", 
        "node" : {
            "tagName" : "li",
            "innerHTML" : "should insert after 2nd item",
            "attributes" : []
        }
    }
  ]
</code></pre>
This would delete the first paragraph, modify the 1st list item in the 1s unordered list and insert a new list item before the 3rd list item in the first unordered list.<p>Of course, there are several limitations:<p>- innerHTML isn't a standard (actually, xmlhttp isn't either afaik)<p>- Dynamically modifying the DOM might interfere with other Javascript present on the page<p>However, this library could be used to unobtrusively implement AJAX without having to write a single line of Javascript (all you would have to do is embedded the script in the header).<p>A use case of this library could be for a blog where you have a link "Show comments". Instead of the browser loading the whole page with blog comments, the request is sent asynchronously to the server script which diffs the current page and the page with comments. It then returns the modifications to the current page and the Javascript then updates the DOM with the information sent by the server script.<p>I had a hard time putting this idea into words and I hope I made myself clear. So far, I've done the Javascript part and what remains is the server side diff script.<p>In a nutshell:<p>- Productivity boost VS writing AJAX by hand, unobtrusive<p>- May interfere with other Javascript code<p>I would appreciate some feedback on the idea!<p>EDIT: This idea came from my frustration of having to wait for the whole DOM to be rendered by web browsers when clicking links within a site. Often times, a big part of the DOM structure remains the same and yet, your browser has to render everything once again. Do you think this "concept" (DIFFing and only rendering what has changed) could be applied directly to the browser to make rendering faster ? The main limitation I see is compatibility problems with Javascript and if the DIFF process would be actually faster.
Ask HN: Review my rapid AJAX idea