Support » Plugin: Minify HTML » Easy way to disable minification for certain calls?

  • Resolved kontur



    the plugin works great and I am more than happy with it. On one recent project I noticed a problem, however. Let’s say I have a page with a download button that triggers a POST action to a page that uses the following code to serve a downloadable zip file “$path” that is read from a (hidden from the user) file on the server and then output for forced download, like so:

    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
    header('Content-Type: application/force-download');
    header('Content-Disposition: inline; filename="' . $filename . '.zip"');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($path));
    header('Connection: close');

    The minification plugin manages to output content before the headers (the minified page that the POST form sent to), and since this output content is included in the served zip file, it obviously breaks that file, although no page is rendered.

    What would you reckon is a good way to exclude minification for these requests that don’t result in an actual page render? Is there some hook I can unhook the minification from for this particular download (i.e. if a particular POST param is present in the current request), which I have myself hooked in ‘init’?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Tim Eckel


    I don’t exactly follow what the problem is, could it be that just removing the “Content-Length” line would resolve the problem?

    Minify HTML only minifies HTML web pages, not file uploads. It shouldn’t cause any issues with uploading. But, I don’t fully follow what you’re doing from this piece of code.

    What the code above does is read in a file and send it to the browser to be downloaded. The content length is gotten from the file that is to be sent, so the browser knows when “all of it” has been transmitted.

    This download code can be called on any kind of page, so let’s assume I have a special URL that is not supposed to actually output anything, since the above headers just tell it to download a file. Visiting that page would result in an empty browser window, sending a POST request from a given page to that URL does not update the current browser page at all – it opens a download dialog, downloads, then closes the dialog.

    The way this code is hooked up to WordPress is via WP’s init hook. In it, it checks if a particular POST parameter is set, and if so, initiates the download and then exit()‘s, staying on the current page.

    How Minify interferes with it is that presumably already by the time the init hook is reached, or in a hook before that, the plugin “catches” all output, which would later on be minified and output. Even though the page that receives the POST parameter does not actually output anything (the exit() after the download code preventing the page form getting anywhere near WP’s output), Minify already started caching that page. Since PHP ends, it probably just dumps the buffered html up to that point – thus interfering with the content output of my download script, which should only be the file content.

    In a nutshell I’d need a way to disable the plugin for particular URLs or REQUEST parameters. What hook does the plugin use to do business – it is hacky but should be possible for me to just “unregister” the plugin activation like that?

    Any update on this?

    Plugin Author Tim Eckel


    This is a very specific issue. I’d probably need to see it first-hand to resolve as I’ve never done anything like you’re doing. If you make changes to the plug to address it, I’d be more that willing to integrate your changes into the source.

    Plugin Author Tim Eckel



Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Easy way to disable minification for certain calls?’ is closed to new replies.