Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Wordpress服务器端使用PHP缩小CSS和JS_Javascript_Php_Css_Wordpress - Fatal编程技术网

Javascript 在Wordpress服务器端使用PHP缩小CSS和JS

Javascript 在Wordpress服务器端使用PHP缩小CSS和JS,javascript,php,css,wordpress,Javascript,Php,Css,Wordpress,我希望将此添加到我的框架中,以进一步优化它。我不想使用插件,我希望代码尽可能轻。这是我目前掌握的代码。如果我只调用“style.css”,这是可行的,但是如果我调用其他文件,它不会缩小文件。我得到的js文件也一样。它会删除空白,但不会完全缩小文件。希望有人能帮忙。谢谢 <?php $dev_master_root = dirname(dirname(dirname(dirname(dirname(__FILE__))))); if ( file_exists( $dev_mast

我希望将此添加到我的框架中,以进一步优化它。我不想使用插件,我希望代码尽可能轻。这是我目前掌握的代码。如果我只调用“style.css”,这是可行的,但是如果我调用其他文件,它不会缩小文件。我得到的js文件也一样。它会删除空白,但不会完全缩小文件。希望有人能帮忙。谢谢

    <?php

$dev_master_root = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
if ( file_exists( $dev_master_root.'/wp-load.php' ) ) {
    require_once( $dev_master_root.'/wp-load.php' );
} elseif ( file_exists( $dev_master_root.'/wp-config.php' ) ) {
    require_once( $dev_master_root.'/wp-config.php' );
}  

/* Add your CSS files to this array (THESE ARE ONLY EXAMPLES) */
$cssFiles = array(
  "../style.css",
  "global.css",
  "slicknav.css"
);

$buffer = "";
foreach ($cssFiles as $cssFile) {
  $buffer .= file_get_contents($cssFile);
}

// Remove comments
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);

// Remove space after colons
$buffer = str_replace(': ', ':', $buffer);

// Remove whitespace
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);

// Enable GZip encoding.
ob_start("ob_gzhandler");

// Enable caching
header('Cache-Control: public');

// Expire in one day
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');

// Set the correct MIME type, because Apache won't set it for us
header("Content-type: text/css");

// Write everything out
echo($buffer);

?>
这是使用minify文件仅调用style.css时的输出。i、 当我删除“global.css”和“slicknav.css”时

因此,在上面的代码中,这只是style.css,但您可以看到所有注释等都被删除。它的重量非常轻,因为所有的基础样式都是从Gualal.CSS

中调用的。 我刚刚注意到这段代码中的空格,我也想删除它们。我以为上面的绳子会这么做


如果你需要更多信息,请告诉我。再次感谢

您是否正确引用了阵列中的文件位置


此外,对于当前代码,它不会执行完全缩小,因为这涉及到将变量名切换为较短的变量名,例如(
someVariableName
将变为
a

除此之外,我建议您阅读以下内容:感谢您的回复,我认为我正确引用了它们。“style.css”位于主主题目录中(根据Wordpress标准),其他css文件位于“css”文件夹中。上面的代码也位于“css”文件夹中。如果我删除其他文件,它会缩小“style.css”,但不会同时删除所有文件。我主要希望将所有文件连接成一个文件,只提供一个缩小的文件。是否值得我提供输出代码?还是它的样本?感谢您,无论是否包含所有脚本,输出示例都会很有帮助
    body {
    color: #2d2e32;
}

h1 {
    font-size: 24px;
}

h2 {
    font-size: 21px;
}

h3 {
    font-size: 18px;
}

h4 {
    font-size: 16px;
}

h5 {
    font-size: 12px;
}

h6 {
    font-size: 11px;
}

h1, h2, h3, h4, h5, h6 {
    line-height: 1.618;
    margin-bottom: 20px;
}

p {
    font-family: 'Domine', serif;
    font-size: 12px;
}

#dev-master-main-container {}

#dev-master-header-container {
    background: #fff;
}

#dev-master-content-container {}

#dev-master-footer-container {
    background: #000026;
}

#dev-master-footer-content {}

@media screen and (max-width :1180px) {}

@media screen and (max-width :960px) {}

@media screen and (max-width :768px) {}

@media screen and (max-width :524px) {}

html {
    font-family: sans-serif;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    height: 100%;
}

body {
    margin: 0;
    height: 100%;
}

article, aside, details, figcaption, figure, footer, header, main, menu,
nav, section, summary {
    display: block;
}

audio, canvas, progress, video {
    display: inline-block;
    vertical-align: baseline;
}

audio:not([controls]) {
    display: none;
    height: 0;
}

[hidden], template {
    display: none;
}

a {
    background-color: transparent;
}

a:active, a:hover {
    outline: 0;
}

abbr[title] {
    border-bottom: 1px dotted;
}

b, strong {
    font-weight: 700;
}

dfn {
    font-style: italic;
}

h1 {
    font-size: 2em;
    margin: .67em 0;
}

mark {
    background: #ff0;
    color: #000;
}

small {
    font-size: 80%;
}

sub, sup {
    font-size: 75%;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
}

sup {
    top: -.5em;
}
h1,h2,h3,h4,h5,h6 {}p {}#dev-master-main-container {}#dev-master-header-container {background:#fff;}#dev-master-content-container {}#dev-master-footer-container {background:#000026;}#dev-master-footer-content {}@media screen and (max-width :1180px) {}@media screen and (max-width :960px) {}@media screen and (max-width :768px) {}@media screen and (max-width :524px) {}