Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Community > MacNN Lounge > Programming Question - WordPress Smart Refresh

Programming Question - WordPress Smart Refresh
Thread Tools
mitchell_pgh
Posting Junkie
Join Date: Feb 2000
Location: Washington, DC
Status: Offline
Reply With Quote
Jun 5, 2013, 09:47 AM
 
OK, I'm not a programmer, but I have a rather basic (aren't they all?) question. So, I have a WordPress blog connected to an event screen (think TV). I'd like the browser connected to the TV to refresh when new content is added to the WordPress site (currently, it simply refreshes every 15 minutes). The new method only needs to check every 2-5 minutes, but currently, the dumb refresh pulls over ~4-10mb per update. Not massive, but it could grow over time.

I'm wide open to suggestions, input, etc.
     
BLAZE_MkIV
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status: Offline
Reply With Quote
Jun 5, 2013, 10:41 AM
 
Poll a dirty flag every 2 minutes and use that to determine if a full get is needed? I don't know wordpress though.
     
mitchell_pgh  (op)
Posting Junkie
Join Date: Feb 2000
Location: Washington, DC
Status: Offline
Reply With Quote
Jun 5, 2013, 11:31 AM
 
Would you do that in javascript or something else?
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jun 5, 2013, 11:40 AM
 
This would require JavaScript and AJAX calls being called over set intervals. It would be hard to do this without interrupting a post you were reading.
     
mitchell_pgh  (op)
Posting Junkie
Join Date: Feb 2000
Location: Washington, DC
Status: Offline
Reply With Quote
Jun 5, 2013, 12:00 PM
 
Originally Posted by besson3c View Post
This would require JavaScript and AJAX calls being called over set intervals. It would be hard to do this without interrupting a post you were reading.
besson3c, thanks! Considering this is an event monitor (that might... MIGHT be updated 1-2 a day, max, and that's a big might) I'm a little less worried about upsetting the viewing experience. Also, most of the updates would happen in the middle of the night or in "emergency" (aka, not in any way an emergency) situations.

Would you be able to point me in the right direction regarding how this might be accomplished?
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jun 5, 2013, 12:13 PM
 
Originally Posted by mitchell_pgh View Post
besson3c, thanks! Considering this is an event monitor (that might... MIGHT be updated 1-2 a day, max, and that's a big might) I'm a little less worried about upsetting the viewing experience. Also, most of the updates would happen in the middle of the night or in "emergency" (aka, not in any way an emergency) situations.

Would you be able to point me in the right direction regarding how this might be accomplished?

Sure!

I would create a new URL/WP page called something like "/eventrefresh" and assign it to a custom template. In this template I would call query_posts() to loop over all of your posts, finding the most recent update date. I would compare this update date to the last update date you have stored in a PHP session variable (or database table, if you'd prefer to be able to quit the browser and therefore destroy the current session). If an update is available you'd output the update date to signal to your AJAX call that a page refresh is needed.

On the Javascript side you would trigger your AJAX call wrapped in a setInterval() wrapper, i.e.

Code:
var refreshtimer = setInterval(function() { ... your AJAX call to /eventrefresh ... }, 5000);
where 5000 is the interval your AJAX call would fire in milliseconds. I suspect that you'd be doing this Javascript in jQuery, but here is the AJAX call in YUI (where my brain is right now):

Code:
YUI().use('io-base', function(Y) { var refreshtimer = setInterval(function() { var cfg = { method:'post', on: { complete:function(id, transport) { if (transport.responseText) { location.reload(); } } } } Y.io('/eventrefresh', cfg); }, 5000); });
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:25 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,