wpsharks / html-compressor

HTML Compressor. Combines and compresses CSS/JS/HTML code.
https://websharks.github.io/html-compressor/
GNU General Public License v3.0
39 stars 11 forks source link

Dynamically update #76

Closed DmitriyKashin closed 8 years ago

DmitriyKashin commented 8 years ago

Hello! Just want to say that dynamically cache update not working right now. That's a big problem for highload services. My setup looks like:

$options=array(); $options['cache_dir_public']=ROOTPATH.'/html-https/htmlc/cache/public'; $options['cache_dir_url_public']= '//sitename.ru/html-https/htmlc/cache/public'; $options['cache_dir_private']= ROOTPATH.'/html-https/htmlc/cache/private'; $html_compressor = new WebSharks\HtmlCompressor\Core($options); ob_start(array($html_compressor, 'compress'));

Head tag for example:

<head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title><?php echo get_text('list:title'); ?></title>
        <meta name="description" content="<?php echo get_text('list:description'); ?>" />
        <meta name="viewport" content="width=1024, initial-scale=1">
        <meta name="referrer" content="no-referrer">
        <link rel="stylesheet" href="http://sitename.ru/css/normalize.css">
        <link type="text/css" rel="stylesheet" href="http://sitename.ru/css/jquery.custom-scrollbar.css">
        <link rel="stylesheet" href="http://sitename.ru/css/main.css">
        <link rel="stylesheet" href="http://sitename.ru/css/font-awesome.min.css">
        <script src="http://sitename.ru/js/vendor/modernizr-2.6.2.min.js"></script>
    </head>

So the problem is that i can remove whole content from modernizr, save it, reload the page and still get old cached modernizr. Thank you!

jaswrks commented 8 years ago

Thanks for the report! :-)

If I understand correctly, this is not a bug, it's the intended functionality. The HTML Compressor doesn't add the expense of checking filemtime() on every single file each time it loads a page. That would slow things down drastically. Instead, it looks at the URLs only.

So if you change a script, you should indicate that by either clearing the cache, or by updating the URL; e.g., providing a version in the URL itself.

<script src="http://sitename.ru/js/vendor/modernizr-2.6.2.min.js?v=2.02"></script>
DmitriyKashin commented 8 years ago

Thank you for response :)