PDA

View Full Version : gAjax RSS Feeds Displayer not Updating?



ShieldofChaos
01-29-2012, 06:26 AM
1) Script Title:
gAjax RSS Feeds Displayer
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex18/gajaxrssdisplayer.htm
3) Describe problem:
I have gotten everything working for this script. However there is a weird problem whereby the RSS feeds on my website will sometime not get updated UNLESS I visit my actual RSS feeds URL.

Is this intended or is this a bug? If you need, I can provide you my sample website that the RSS feeds reside inside.

Additional Information:
I am using a modified javascript version of the RSS feeds displayer done by jscheuer1 at this forum help page, http://www.dynamicdrive.com/forums/showthread.php?t=67155. The modified version of the javascript basically display the author of the RSS feeds.

Besides the modified javascript, these are the HTML codes that I used on my website,


<script type="text/javascript" src="http://www.google.com/jsapi?key=API code removed by me">
</script>

<script type="text/javascript" src="http://shadowinc.zymichost.com/rss/gfeedfetcher.js">

/***********************************************
* gAjax RSS Feeds Displayer- (c) Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

</script>

<style type="text/css">

.labelfield{ /*CSS for label field in general*/
color:brown;
font-size: 90%;
}

.datefield{ /*CSS for date field in general*/
color:#666666;
font-size: 100%;
}

#example1 a{ /*CSS specific to demo 3*/
color: #D80101;
text-decoration: none;
font-weight: bold;
}

#example1 p{ /*CSS specific to demo 3*/
margin-bottom: 20px;
}

</style>


<script type="text/javascript">

var newsfeed=new gfeedfetcher("example1", "example1class", "_new")
newsfeed.addFeed("Sample", "URL Removed by Me") //Specify "label" plus URL to RSS feed
newsfeed.displayoptions("datetime author description") //show the specified additional fields
newsfeed.setentrycontainer("p") //Display each entry as a paragraph
newsfeed.filterfeed(10, "date") //Show 8 entries, sort by date
newsfeed.init() //Always call this last

</script>

Thanks!

jscheuer1
01-29-2012, 03:40 PM
The feed is being cached somewhere. Try this where you have the:


newsfeed.addFeed("Sample", "URL Removed by Me" + '?bustcache=' + new Date().getTime()) //Specify "label" plus URL to RSS feed

add the highlighted. But if your feed URL already has a query string with a ? in it, make that:


newsfeed.addFeed("Sample", "URL Removed by Me" + '&bustcache=' + new Date().getTime()) //Specify "label" plus URL to RSS feed


If that takes care of the problem we can make it a part of the gfeedfetcher.js script.

Once that change is made, you will no longer need the highlighted in the on page call. In fact, it should only be done one place or the other, not both. But test it on the page first to see if it works. No sense updating the script if it doesn't help.

And, since fetching the feed from cache is a feature of this service as provided by Google, it might be best to only do it on the page for feeds that you deem require it. Google is caching the feed to limit its bandwidth exposure. From checking Google Groups on this topic, the cache is supposed to be updated every hour, but respondents claim it can often be much longer.

So before you do anything, see if it updates on its own after an hour.

You might also want to check if your server is caching the feed. This solution may or may not help with that.

ShieldofChaos
01-29-2012, 04:38 PM
Thanks alot! I will be trying out and post the result back soon.

I have a question though, when you said feed URL with a query string, is this a URL that has a query string on it?

http:// -website url removed by me- /feed/?f=3

jscheuer1
01-29-2012, 05:26 PM
Yes it is. Use the version with the & symbol for that.

ShieldofChaos
01-31-2012, 11:51 PM
Hi John,

After two days of testing out, it seems like the code is working. The RSS feeds are updating on their own now. :)

Can I continue to use this code at my HTML or should I integrate it into the gfeedfetcher.js? If so, how should I integrate it?

Thanks for the help!

jscheuer1
02-01-2012, 05:24 AM
We can update the script. Find the gfeedfetcher.prototype.addFeed function in gfeedfetcher.js and replace it with this one:


gfeedfetcher.prototype.addFeed=function(label, url, bustcache){
if(bustcache){
bustcache = /\?/.test(url)? '&' : '?';
url = url + bustcache + 'bustcache=' + new Date().getTime();
}
this.feedlabels[this.feedlabels.length]=label;
this.feedurls[this.feedurls.length]=url;
}

Now, instead of adding '? or '& and bustcache=' + new Date().getTime() you can simply specify true or false as the third parameter when invoking addFeed. So if you had:


newsfeed.addFeed("Sample", "URL Removed by Me" + '?bustcache=' + new Date().getTime()) //Specify "label" plus URL to RSS feed

or:


newsfeed.addFeed("Sample", "URL Removed by Me" + '&bustcache=' + new Date().getTime()) //Specify "label" plus URL to RSS feed

Make it:


newsfeed.addFeed("Sample", "URL Removed by Me", true) //Specify "label" plus URL to RSS feed, optional bustcache (true/false)

If you don't want to bust the cache, use false or put nothing there, not even the comma.

I should note again that Google is caching these feeds to save on their bandwidth. So it makes sense to only take this sort of measure with feeds that update frequently, and/or that when they do update are presenting time sensitive information.

If updates are infrequent and done manually, one could edit the addFeed line on an as needed basis, setting the bust cache to true for a few days only when the feed is updated.

ShieldofChaos
02-01-2012, 01:52 PM
Thanks John!

Will put them in my JS when I am doing the finalization of my website coding. :)