Note that there are some explanatory texts on larger screens.

plurals
  1. POCompression and mergin of JS files with PHP- Text editor
    text
    copied!<p>I am currently working with minification of JS files for improvement of page speed. I have been able to find the simplest method that works with almost all my js files in exception of two. The problem is with the js files for a wmd editor I am trying to implement to my site. The js files <code>wmd.js</code> and <code>showdown.js</code> are not being compressd and cache by the function in <code>scripts.php</code>. I checked with firebug tool, in the response header of <code>scripts.php</code> neither file is included in the final compressed js file.</p> <p>What is the issue with my process of compressing these js files(wmd &amp; showdown) and combining it into one? <a href="http://jachamboneth.cpsc3430.ausrc.org/wmdXss/default.php" rel="noreferrer">EXAMPLE SITE</a></p> <p><strong>js/scripts.php- takes care of compression and cache of js files</strong></p> <pre><code>&lt;?php error_reporting(E_ERROR); // see http://web.archive.org/web/20071211140719/http://www.w3.org/2005/MWI/BPWG/techs/CachingWithPhp // $lastModifiedDate must be a GMT Unix Timestamp // You can use gmmktime(...) to get such a timestamp // getlastmod() also provides this kind of timestamp for the last // modification date of the PHP file itself function cacheHeaders($lastModifiedDate) { if ($lastModifiedDate) { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &amp;&amp; strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) &gt;= $lastModifiedDate) { if (php_sapi_name()=='CGI') { Header("Status: 304 Not Modified"); } else { Header("HTTP/1.0 304 Not Modified"); } exit; } else { $gmtDate = gmdate("D, d M Y H:i:s \G\M\T",$lastModifiedDate); header('Last-Modified: '.$gmtDate); } } } // This function uses a static variable to track the most recent // last modification time function lastModificationTime($time=0) { static $last_mod ; if (!isset($last_mod) || $time &gt; $last_mod) { $last_mod = $time ; } return $last_mod ; } lastModificationTime(filemtime(__FILE__)); cacheHeaders(lastModificationTime()); header("Content-type: text/javascript; charset: UTF-8"); ob_start ("ob_gzhandler"); foreach (explode(",", $_GET['load']) as $value) { if (is_file("$value.js")) { $real_path = mb_strtolower(realpath("$value.js")); if (strpos($real_path, mb_strtolower(dirname(__FILE__))) !== false || strpos($real_path, mb_strtolower(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR)) !== false) { lastModificationTime(filemtime("$value.js")); include("$value.js");echo "\n"; } } } ?&gt; </code></pre> <p><strong>The way i am calling the compressed.js</strong></p> <pre><code>&lt;script type = "text/javascript" src = "js/scripts.php?build=12345&amp;load=wmd,showdown"&gt;&lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload