JS异步加载方式方便用于网站维护,不至于打开页面一直在加载状态,具体实现在前端html页面文件添加如下JS代码
<script type="text/javascript"> function downloadJSAtOnload() { var srcdel = document.createElement("script"); //异步加载的url地址 srcdel.src = "{url('index/coll/del')}"; document.body.appendChild(srcdel); //执行多个异步任务,再次创建script标签 var srchdk = document.createElement("script"); srchdk.src = "{url('index/coll/haodk')}"; document.body.appendChild(srchdk); var srcdtk = document.createElement("script"); srcdtk.src = "{url('index/coll/dtaok')}"; document.body.appendChild(srcdtk); } if (window.addEventListener) window.addEventListener("load", downloadJSAtOnload, false); else if (window.attachEvent) window.attachEvent("onload", downloadJSAtOnload); else window.onload = downloadJSAtOnload; </script>
相对应的后台实现任务处理方式案列
//删除过期券信息 public function del(){ $delt=BASE_PATH.'data/del.t'; //12个小时进行清理一次 if(time()-filemtime($delt)>43200){ $m=obj('api/ApiData'); $t=time()+3600; $where='`quan_end`<'.$t; $m->Deletethis('coupon', $where); //删除一个月前的搜索记录 $t=time()-2592000; $where='`searchtime`<'.$t; $m->Deletethis('search_keywords', $where); touch($delt); } }
如果本文对你有帮助,欢迎打赏本站