Emlog无插件实现网站源代码压缩教程 转自东镜SEO

    选择打赏方式

在以往的Emlog优化教程中,相信给长朋友们提供的都是使用的代码压缩插件

今天冬镜博客主要是分享插件的代码版本,即不使用插件直接将代码写进module.php中就可以

偷偷笑笑又成功的消灭一个插件

网站源代码压缩代码一:

首先我们找到模版文件夹下的module.php文件并打开 添加如下代码

function em_compress_html_main($buffer){ $initial=strlen($buffer); $buffer=explode("<!--em-compress-html-->", $buffer); $count=count ($buffer); for ($i = 0; $i <= $count; $i++){ if (stristr($buffer[$i], '<!--em-compress-html no compression-->')){ $buffer[$i]=(str_replace("<!--em-compress-html no compression-->", " ", $buffer[$i])); }else{ $buffer[$i]=(str_replace("\t", " ", $buffer[$i])); $buffer[$i]=(str_replace("\n\n", "\n", $buffer[$i])); $buffer[$i]=(str_replace("\n", "", $buffer[$i])); $buffer[$i]=(str_replace("\r", "", $buffer[$i])); while (stristr($buffer[$i], '  ')) { $buffer[$i]=(str_replace("  ", " ", $buffer[$i])); } } $buffer_out.=$buffer[$i]; } $final=strlen($buffer_out); $savings=($initial-$final)/$initial*100; $savings=round($savings, 2); $buffer_out.="\n<!--压缩前的大小: $initial bytes; 压缩后的大小: $final bytes; 节约:$savings% -->"; return $buffer_out; }
然后在找到模版文件夹下的footer.php文件并打开 添加如下代码
<?php if(_g('compress_html')=='open'){ $html=ob_get_contents(); ob_get_clean(); echo em_compress_html_main($html); } ?>

网站源代码压缩代码二:

首先我们找到模版文件夹下的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);?>

Emlog无插件实现网站源代码压缩

如果你想要实现不压缩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); ?>
然后找到模版文件夹下的echo_log.php(文章内容页面)、page.php(评论页面)文件中的$log_content 用下面代码替换掉
slbys($log_content)




版权声明:若无特殊注明,本文皆为《 Macro 》原创,转载请保留文章出处。
本文链接:Emlog无插件实现网站源代码压缩教程 转自东镜SEO https://blog.julym.com/sharetutorial/354.html
百度收录情况: 百度已收录,详情
正文到此结束

热门推荐

发表吐槽

你肿么看?

你还可以输入 250 / 250 个字

嘻嘻 大笑 可怜 吃惊 害羞 调皮 鄙视 示爱 大哭 开心 偷笑 嘘 奸笑 委屈 抱抱 愤怒 思考 日了狗 胜利 不高兴 阴险 乖 酷 滑稽

评论信息框

吃奶的力气提交吐槽中...

已有35条吐槽

Scouse

2024-07-07 16:02 俄罗斯 CZ88.NET
坐在家里赚点钱。] https://t.me/cryptaxbot/17?Phewshags82doX
 Windows 10 x64   SRWare Iron Safari

Scouse

2024-07-07 05:40 俄罗斯 CZ88.NET
小额投资可以很快带来成吨的美元。 https://t.me/cryptaxbot/17?Phewshags96doX
 Windows 10 x64   Google Chrome 114.0.0.0

Scouse

2024-07-06 09:45 俄罗斯 CZ88.NET
即使你睡觉,金融机器人也为你工作。] https://t.me/cryptaxbot/17?Phewshags64doX
 Windows 8.1 x64   Google Chrome 103.0.5060.66

Scouse

2024-07-05 06:18 俄罗斯 CZ88.NET
看着你的钱增长,而你与机器人投资。 https://t.me/cryptaxbot/17?Phewshags84doX
 Windows 10 x64   Google Chrome 114.0.0.0

Scouse

2024-07-04 18:35 俄罗斯 CZ88.NET
注意! 金融机器人可能会给你带来数百万!] https://t.me/cryptaxbot/17?Phewshags11doX
 Windows 8.1 x64   Google Chrome 103.0.5060.53

Scouse

2024-07-04 17:50 俄罗斯 CZ88.NET
每周在这里在线工作数千人。] https://t.me/cryptaxbot/17?Phewshags82doX
 Windows 10 x64   Google Chrome 121.0.0.0

Scouse

2024-07-03 03:34 俄罗斯 CZ88.NET
哇塞! 这是实现财务独立的最快方法。 https://t.me/cryptaxbot/17?Phewshags12doX
 Windows 7 x64   Google Chrome 114.0.5735.289

Scouse

2024-07-02 12:22 俄罗斯 CZ88.NET
即使是一个孩子也知道如何在这个机器人的帮助下赚100美元。] https://t.me/cryptaxbot/14?Phewshags68doX
 Windows 10 x64   SRWare Iron Safari

Scouse

2024-07-02 11:06 俄罗斯 CZ88.NET
财务独立是这个机器人的保证。] https://t.me/cryptaxbot/14?Phewshags19doX
 Windows 7 x64   Google Chrome 103.0.0.0

Scouse

2024-06-28 21:37 俄罗斯 CZ88.NET
开始每周只用这个机器人赚几千美元。 https://t.me/cryptaxbot/14
 Windows 10 x64   SRWare Iron Safari