简体   繁体   English

在Wordpress子主题中使用PHP压缩脚本缩小CSS和JS

[英]Minify css and js with PHP compression script in Wordpress child-theme

I want to use next PHP script to serve combined, pre-gzipped and minified JS and CSS files. 我想使用下一个PHP脚本来提供组合,预压缩和缩小的JS和CSS文件。 source code is available here: https://code.google.com/p/compress/ 源代码可在以下位置找到: https//code.google.com/p/compress/
There is a WAMP localhost with wordpress installed. 有一个安装了wordpress的WAMP本地主机。
And what I have done: 我所做的:

  • added three files (jsmin.php, cssmin.php, compress.php) in child-theme's folder; 在子主题文件夹中添加了三个文件(jsmin.php,cssmin.php,compress.php);

  • added directory 'min' in child-theme folder; 在子主题文件夹中添加目录“ min”;

  • created file 'compress_timestamp.php' 创建文件'compress_timestamp.php'

  • added code below into header.php (tried functions.php then tried first line of header.php) 将以下代码添加到header.php中(尝​​试过functions.php,然后尝试了header.php的第一行)

    require_once('compress_timestamp.php'); //load timestamp created by compress.php module sets field $compress_stamp=unix_timestamp
    if (stripos($_SERVER['HTTP_ACCEPT_ENCODING'],'GZIP')!==false)
    $gz='gz'; else $gz=null; echo '<link rel="stylesheet" type="text/css" href="min/css_schedule_'.$compress_stamp.'.css'.$gz.'" />',PHP_EOL; // the following scripts were combined into css_schedule // echo '<link rel="stylesheet" type="text/css" href="CSS/menu.css" />',PHP_EOL; // echo '<link rel="stylesheet" type="text/css" href="CSS/ThreeColumnFixed.css" />',PHP_EOL; // echo '<link rel="stylesheet" type="text/css" href="CSS/sprite.css" />',PHP_EOL; // echo '<link rel="stylesheet" type="text/css" href="CSS/iCal.css" />',PHP_EOL;


  • changed lines accordingly to child-theme and parent folders: 相应地更改了子主题和父文件夹的行:

      echo '<link rel="stylesheet" type="text/css" href="style.css" />',PHP_EOL; echo '<link rel="stylesheet" type="text/css" href="../twentyfourteen/style.css" 

What was missed and what is the right way to make it work? 遗漏了什么,使它起作用的正确方法是什么?
And finally when all is done how to launch that script remotely on XAMP (VPS)? 最后,完成所有操作后,如何在XAMP(VPS)上远程启动该脚本?

There is a really good WordPress plugin, called JCH Optimize , that minify css and javascript. 有一个非常好的WordPress插件,称为JCH Optimize ,可以最小化css和javascript。 Its very easy to install. 它非常容易安装。 It has both a free and paid version that comes with a ton more features that can be used to speed up your wordpress site. 它既有免费版本又有付费版本,并具有许多可用来加速您的wordpress网站的功能。 They also support Joomla. 他们还支持Joomla。

The support for it is really good too. 对它的支持也确实很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM