Closed halukkaramete closed 2 years ago
The ?version=
is the right idea.
I usually put a hash of the content as the version instead of a date. That way you know if it truly changed.
Computing hash from file io can be expensive so you can have a cache of that on the server.
I think cache: true
will still respect downloading new version. (New url = new file)
I can confirm that attaching the version DEFINITELY works and cache:true does not cause any problem. cache: true still respects the version number. If the version number did not change, then cache:true allows you to read content from cache. If the number has changed, I do notice the delay of downloading the requested content.
setsource("https://... blah.blah.js?version=<?php echo blp_getFileModifDate('/...blah...blah.js');?>");
is the best way to handle it.
function blp_getFileModifDate($filePath) {
// you can hit this with the f:// start or / start.
// it can resolve the file name either way.
if ( blp_startsWith($filePath,'/')) {
$filePath = YOUR_SERVER_ROOTPATH_HERE_WITHOUT_THE_FINAL_SLASH . $filePath;
if ( !file_exists($filePath)) {
return 0;
}
} else {
if ( !file_exists($filePath)) {
return 0;
}
}
// if we are here, that means the file name has been resolved and found.
return filemtime($filePath);
}
The next improvement would be to deploy some sort of the gzip'ping on the fly, which I will explore next. And this SO may have the answer: https://stackoverflow.com/questions/6478304/zip-a-json-object-before-sending-in-php
For setting the source and initializing the fuzzyhound, we do this.