Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minify returns white page after source file changes

Tags:

php

minify

Minify works fine for me, but after changing one of the source files, I receive a white empty page. Refreshing the page does not change anything. Refreshing without caching (Strg + F5) solves the problem. After one refresh without caching, I can go back refreshing with caching and it works.

The URL im calling looks like this:

dev/min/min.php/js?type=js&src%5B0%5D=ewOutlibs%2Fjquery.min.js&src%5B1%5D=ewOutlibs%2Fcookie%2Fjquery.cookie.js

min.php

<?php
define('MINIFY_MIN_DIR', dirname(__FILE__));

// load config
require MINIFY_MIN_DIR . '/config.php';

// autoload
require $min_libPath . "/Minify/Loader.php";
Minify_Loader::register();

// caching
Minify::setCache(
    isset($min_cachePath) ? $min_cachePath : ''
    ,$min_cacheFileLocking
);

// get files to merge
$aSrc = $_GET['src'];

// replace shortened url with long url
if (isset($_GET['type']) && $_GET['type'] === 'js') {
    $aSrc = str_replace('ewOut', '//out/xxx/src/js/', $aSrc);
}

// build array
$aSources = array(
    'files' => $aSrc,
    'maxAge' => 31536000 // one year
);

try {
    // compress, merge and serve new file
    Minify::serve('Files', $aSources);
} catch (Exception $e) {
    echo $e->getMessage();
}

Request Header:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:oxidadminprofile=0%40Standard%4010%401; oxidadminlanguage=de; sid_key=oxid; language=0; sid=crlrs8bqg21g6e33arsjq708k4; ZDEDebuggerPresent=php,phtml,php3
Host:dev.teltec
If-Modified-Since:Tue, 04 Aug 2015 12:35:59 GMT
If-None-Match:"pub1438691759;gz"
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36

Response Header:

HTTP/1.1 304 Not Modified
Date: Tue, 04 Aug 2015 12:36:04 GMT
Server: Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/0.9.8o mod_fcgid/2.3.9
Connection: Keep-Alive
Keep-Alive: timeout=5, max=99
ETag: "pub1438691759;gz"
Expires: Wed, 03 Aug 2016 12:36:04 GMT
Cache-Control: max-age=31536000
Vary: Accept-Encoding
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
like image 478
Chris Avatar asked Aug 04 '15 12:08

Chris


2 Answers

This is because the server and/or browser is caching it. You invalidate the cache when the source updates, but the browser thinks it's still cached, tries to reference it, shows blank until you force a refresh (ctrl+F5). A way around it is to make the URL you use to access it unique by way of a "version" number. Microsoft uses it with their bundles (the hash changes if the source file changed) which automatically tells the browser to go fetch a "new" copy of it.

I had the same problem with XML feeds I was providing to a client who kept getting the same copy of it until I just added a version number at the end forcing the browser to always fetch a new file

like image 125
user3036342 Avatar answered Oct 20 '22 23:10

user3036342


The tmp directory on the stage system was not writeable, so Minify failed caching the files and returned a white page. Silly mistake. Locally worked fine, because the tmp directory worked as expected.

like image 36
Chris Avatar answered Oct 20 '22 22:10

Chris