I'm using this function to remove HTML comments from my code to save loading time:
// Remove unwanted HTML comments
function remove_html_comments($content = '') {
return preg_replace('/<!--(.|\s)*?-->/', '', $content);
}
But I also use wt3 cache plugin witch uses this to parse code inside his comment pattern:
$buffer = preg_replace_callback('~<!--\s*mfunc\s*' . W3TC_DYNAMIC_SECURITY . '(.*)-->(.*)<!--\s*/mfunc\s*' . W3TC_DYNAMIC_SECURITY . '\s*-->~Uis', array(
&$this,
'_parse_dynamic_mfunc'
), $buffer);
I need to implement fragment caching to exclude some parts of my code from being cached, but that is not possible with the function that I use to strip code commenting because it will exclude all comments...
Is it possible to exclude all comments inside W3TC comment tags from being removed by the function that i'm using?
This is how I'm implementing on my theme:
In wp-config.php I've added
define( 'W3TC_DYNAMIC_SECURITY', md5( rand( 0, 999999 ) ) ); // random "secret"
In my template:
<!--mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->
<?php echo rand(0,1000); ?>
<!--/mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->