Plugin Support
qtwrk
(@qtwrk)
Hi,
what is exactly are you referring to as cache burst
?
Best regards,
Thread Starter
ceap80
(@ceap80)
Hi, let’s say I have this in the head section of my template
<link rel="stylesheet" type="text/css" href="<?php bloginfo('url') ?>/app/assets/css/common.css?version=30" />
before the latest change changing the version parameter to something like version=31
instructed the plugin to generate a new filename.
With the latest change no matter what value the version parameter has, the plugin will generate the same file name as is ignoring the query string completely.
Plugin Support
qtwrk
(@qtwrk)
Hi,
it is generated based on file content’s md5sum value
and why would you want to change/update/regenerate if the file content is same ?
Best regards,
Thread Starter
ceap80
(@ceap80)
it is generated based on file content’s md5sum value
That seems to be the case when the plugin is combining the files but if the plugin is only doing file minification it ends up hitting _build_single_hash_url
function
/**
* Build a single URL mapped filename (This will not save in DB)
* @since 4.0
*/
private function _build_single_hash_url( $src, $file_type = 'css' ) {
$content = $this->__optimizer->load_file( $src, $file_type );
$is_min = $this->__optimizer->is_min( $src );
$content = $this->__optimizer->optm_snippet( $content, $file_type, ! $is_min, $src );
// Save to file
$filename = $file_type . '/' . md5( $this->remove_query_strings( $src ) ) . '.' . $file_type;
$static_file = LITESPEED_STATIC_DIR . '/' . $filename;
File::save( $static_file, $content, true );
// $qs_hash = substr( md5( $src ), -5 );
// return LITESPEED_STATIC_URL . "/$filename?ver=$qs_hash";
// $qs_hash is from src, same as $filename, redundant
return LITESPEED_STATIC_URL . "/$filename";
}
Here it seems the md5 is being generated based on the file url and not on the file content
-
This reply was modified 2 years, 7 months ago by ceap80.
-
This reply was modified 2 years, 7 months ago by ceap80.
Plugin Support
qtwrk
(@qtwrk)
yes but for minify , as you can see
md5( $this->remove_query_strings( $src ) )
md5sum value based file name with query string removed
so you have file like test.css?version=1
, it will be used like test.css
only
Thread Starter
ceap80
(@ceap80)
And that is precisely the issue, if I make a change to the file the name generated by the plugin will stay the same. So if I use a very long cache time for the assets the browser will not pick up the changes. The solution here is to use the content for the md5 thus changing the generated file name automatically or at least not ignoring the query string so I can change it when I make some changes to the file. Just like it was working in the 4.3 version.
I’ll copy here for reference, the function from the version 4.3
/**
* Build a single URL mapped filename (This will not save in DB)
* @since 4.0
*/
private function _build_single_hash_url( $src, $file_type = 'css' ) {
$content = $this->__optimizer->load_file( $src, $file_type );
$is_min = $this->__optimizer->is_min( $src );
$content = $this->__optimizer->optm_snippet( $content, $file_type, ! $is_min, $src );
// Save to file
$filename = $file_type . '/' . md5( $this->remove_query_strings( $src ) ) . '.' . $file_type;
$static_file = LITESPEED_STATIC_DIR . '/' . $filename;
File::save( $static_file, $content, true );
$qs_hash = substr( md5( $src ), -5 );
return LITESPEED_STATIC_URL . "/$filename?ver=$qs_hash";
}
Plugin Support
qtwrk
(@qtwrk)
thanks, I will pass the case to our devs
Thanks for the good catch. This is fixed in v4.4.1-a3.
Thread Starter
ceap80
(@ceap80)
Your welcome! And thanks for the quick response.