Patreon LogoYour support makes Blue Moon possible (Patreon)

New PM Notifier (Suggestion)

Status
Not open for further replies.

thy secret

Banned
Banished
Joined
Jul 27, 2013
Being the curious person that I am, I decided to have a look at the Automatic PM notifier you have on this site.

Essentually, you're calling an Ajax request to a page, that outputs a page, depending whether or not you have a private message.
The thing is, the page your outputting is being called every 6 seconds, per tab that's open. When there's no new PM, it's not very much data being sent, and it's only taking about 100 ms to process whether or not you have a new PM... Though, at the same time, you're having the server send a table that's projected onto someone's screen, when you have a new message, which means more data to process, and a longer page being loaded... And not just that. The page is being loaded again and again, every 6 seconds.

I have a suggestion for this...

Instead of sending the entire div and image as a response to the Ajax request, how about instead, just sending a number? The number of PMs unread (or a blank page for 0), and then having the client build the table up.
You can have the template of the PM table, either as a Javascript variable, or maybe something like
Code:
<script type="text/template" id="PMTemplate">
<!--
You have %NUM% new PMs!
//-->
</script>
Only with the whole table and everything. Like this, it'll be invisible to everyone, (and it's not even being processed) and it's NOT being called every 6 seconds...

In this way, the ajaxpmnotice function will look more like...
Code:
<script type="text/javascript">
<!--
function ajaxpmnotice()
{
	new Ajax.Request
	(
		'http://bluemoonroleplaying.com/forums/pm.php',
		{
			method:'get',onComplete:function(request)
			{
				if(request.respons != "")
				{
					var Output = replace(/^<!--(.*)//-->$/,"$1"$('PMTemplate').innerHTML); //Strip out the Comments
					Output = replace("%NUM%",request.response,Output);//Input the number
					$('ajaxpmnotice').innerHTML=Output;
				}
				else //0, or no response text at all...
				{
				$('ajaxpmnotice').innerHTML="";
				}
			}
		}
	);
}
ajaxpmnotice();
setInterval("ajaxpmnotice()",6000);
// -->
</script>
Of you could also have all the text part be parsed, as %TEXT%, and have it so if you have only 1 new PM, it says "You have a new PM",


Of course, the part about the output isn't the exact look. I was just giving an idea.
PS, You never adapted the CSS styling for the Code tag xD It's basically grey/white text on a white background. I had to make the text red to be readable.
 
Status
Not open for further replies.
Back
Top Bottom