So far, I know that I can seperate static and dynamic content using AJAX, so if a blog post has a comment update, the article does not have to be redownloaded (it'd be 304), only the comments. Now, I'm thinking of persisting the fetched dynamic content so that next time, only new comments have to be requested. Is there any way to do this without relying on Flash/Gears/HTML5Storage or other plugins?
EDIT: Let's say the comments section on the article looks like this:
<div class='comments' id='comments'>
<a name='comments'></a>
<h4>43 comments:</h4>
<dl id='comments-block'></dl>
<p class='comment-footer'>
<a href='http://example.org/postcomment' onclick=''>Post a Comment</a>
</p>
</div>
on which, an AJAX call to fetch the comments will append them to the <dl id='comments-block'>
, which contains the following snippet:
<div class='comments-singleblock'>
<dt class='comment-author' id='comment-5378479254070788764'>
<a name='comment-5378479254070788764'></a>
Anonymous coward
<span class='comment-timestamp'>
<a href='#comment-5378479254070788764' title='comment permalink'>
5 February 2012 16:52
</a>
</span>
</a>
</dt>
<dd class='comment-body'>
<p>
Your lorum is my ipsum, the dolor is sit amet us.
</p>
</dd>
<dd class='comment-footer'>
Which eternal lies, that is not death.
</dd>
</div>
which can be cached. The subsequent AJAX calls should return only new contents, appending to the above. Now when the article is loaded, the logic is as such
So the question is on how to modify the cached content to include the ones between timestamp A and B.
create a local variable to store the JSON result of your ajax call.
create a local variable to store the Max_Last_Modified_Date.
create a javascript helper that will draw the JSON result.
create a server-side handler that will tell you MAX(LastModifiedDate) of your comments.
create a server-side handler that will return the comments in JSON for
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With