I am using drupal for website. I have written custom module which is showing notification in browser and also open pop-up in website.
I am using JavaScript function which is being called every 15 second or less if condition is false or error comes.
The problem is if there 5 pages is open then on all pages set timeout function is calling every 15 sec or less on all pages and making site slow or break the site.
Please give some instruction to improve the performance of this site.
(function ($) {
$(function() {
// ä»»ä½•éœ€è¦æ‰§è¡Œçš„js特效
setTimeout("countSecond2()", 15000);
$('body').on('click','#popClose',function(event){
//jQuery(".pop_content_message").click(function() {
$(this).parents('#pop').remove();
});
});
})(jQuery);
function countSecond() {
var data = '';
var need_delay = 0;
var js_common_messages_popup = '/messages/popup';
jQuery.ajax({
url: js_common_messages_popup,
type : "post",
dataType : "text",
data : data,
async: true,
success: function(msg) {
var Obdata = jQuery.parseJSON(msg);
if(Obdata !=null){
//alert('1p='+JSON.stringify(msg));
var call = Obdata.call;
var output = Obdata.output;
var selectbox = Obdata.selectbox;
var checkbox = Obdata.checkbox;
var url = Obdata.url;
var need_delay = Obdata.need_delay;
if (call == '1') {
browser_notification(Drupal.t('You have a new reminder'), '', url);
jQuery('#id_pop_task').prepend(output);
jQuery('#id_pop_task .pop_content_message').show();
/*jQuery('#id_pop_task').html(output);
jQuery('#pop').show();
jQuery("#popClose").click(function() {
jQuery('#pop').hide();
});*/
if (selectbox == '1') {
//jQuery("#antiStress").selectbox();
jQuery("[id=antiStress]").selectbox();
}
if (checkbox == '1') {
jQuery('.customR input[type="checkbox"]').ezMark({checkboxCls: "ez-checkbox-green", checkedCls: "ez-checked-green"});
}
setTimeout("countSecond2()", 15000);
}else {
countSecond2();
}
}
else {
countSecond2();
}
},
beforeSend: function() {
//jQuery('#loading').hide();
},
complete: function() {
},
error: function() {
countSecond2();
//location.reload();
}
});
}
function countSecond2() {
var data = '';
var need_delay = 0;
var js_common_messages_popup = '/messages/popup2';
jQuery.ajax({
url: js_common_messages_popup,
type : "post",
dataType : "text",
data : data,
async: true,
success: function(msg) {
var Obdata = jQuery.parseJSON(msg);
if(Obdata !=null){
//alert('2p='+JSON.stringify(msg));
var call = Obdata.call;
var output = Obdata.output;
var selectbox = Obdata.selectbox;
var checkbox = Obdata.checkbox;
var url = Obdata.url;
var need_delay = Obdata.need_delay;
if (call == '1') {
browser_notification(Drupal.t('You have a new reminder'), '', url);
jQuery('#id_pop_task').prepend(output);
jQuery('#id_pop_task .pop_content_message').show();
/*jQuery('#id_pop_task').html(output);
jQuery('#pop').show();
jQuery("#popClose").click(function() {
jQuery('#pop').hide();
});*/
if (selectbox == '1') {
//jQuery("#antiStress").selectbox();
jQuery("[id=antiStress]").selectbox();
}
if (checkbox == '1') {
jQuery('.customR input[type="checkbox"]').ezMark({checkboxCls: "ez-checkbox-green", checkedCls: "ez-checked-green"});
}
setTimeout("countSecond2()", 15000);
}else {
countSecond();
}
}
else {
countSecond();
}
},
beforeSend: function() {
//jQuery('#loading').hide();
},
complete: function() {
},
error: function() {
countSecond();
//location.reload();
}
});
}