前言:
AIDE技术网今天教大家学会Emlog无插件实现全站源码压缩技术
在以往的Emlog优化教程中相信都是使用的代码压缩插件
今天主要是分享插件的代码版本也就是不使用插件
正文:
直接将代码写在模版文件中就可以了
Emlog无插件实现全站源码压缩步骤如下
一、找到模版文件module.php并且打开编辑
添加如下代码(直接复制进去就行)
<?php //全站代码压缩 function slys($sheli){$initial=strlen($sheli);$sheli=explode(“<!–slys–>”,$sheli);$count=count($sheli); for($i=0;$i<=$count;$i++){if(stristr($sheli[$i], ‘<!–slys end–>’)){$sheli[$i]=(str_replace(“<!–slys end–>”, ” “, $sheli[$i]));}else{$sheli[$i]=(str_replace(“\t”, ” “, $sheli[$i]));$sheli[$i]=(str_replace(“\n\n”, “\n”, $sheli[$i]));$sheli[$i]=(str_replace(“\n”, “”, $sheli[$i]));$sheli[$i]=(str_replace(“\r”, “”, $sheli[$i]));while (stristr($sheli[$i], ‘ ‘)){$sheli[$i]=(str_replace(” “, ” “, $sheli[$i]));}}$sheli_out.=$sheli[$i];}$final=strlen($sheli_out);$savings=($initial–$final)/$initial*100;$savings=round($savings,2);$sheli_out.=“\n<!–压缩前的大小: $initial bytes; 压缩后的大小: $final bytes; 节约:$savings% –>”;return $sheli_out;}
二、找到并且打开模版文件footer.php,在最末尾(即后面)添加下面的代码挂载点
<?php $html=ob_get_contents();ob_get_clean();echo slys($html);?>
到这里就已经实现了全站压缩了,也就是说网站代码压缩的教程其实已经结束了
但是考虑到很多用户不需要压缩文章内代码区和页面评论区域
所以接下来看下面的扩展
1、要实现不压缩pre中的代码(即文章页的代码区域)
要在模版文件module.php里面的加入下面代码
<?php //不压缩pre function slbys($content){if(preg_match_all(‘/(crayon-|<\/pre>)/i’,$content,$matches)){$content = ‘<!–slys–><!–slys end–>’.$content;$content.= ‘<!–slys end–><!–slys–>’;}return $content;}slbys($log_content);?>
2、找到并且打开模版文件echo_log.php(文章页模版)、page.php(评论模版)
找到如下代码
$log_content
将其替换为
slbys($log_content)
资源均来自第三方,谨慎下载,前往第三方网站下载 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com 解压密码:www.xkwo.com