I'm developing a mechanism in PHP
that performs a cache of CSS
files in order to decrease the number of requests
of a page and the loading time.
CSS
load file set and if it does not exist it will create a file that is unique and includes the contents of all CSS
.
For the file name I use a hash that results from evaluating the contents of each file. So if someone changes a character that is a new file it will be generated, which will only happen during development and move with CSS
.
This mechanism is much more advantageous than having a request for every CSS
. You can greatly reduce the load time of a page and especially the number of requests of the page.
CSS
is time consuming but for me it seems to me the only way to ensure that if any CSS
changes, the cache will always have the expected content. I use for performance issues the hash_file
function within a cycle:
$fhash .= hash_file('crc32b', $filepath);
Is there any better performance function for this job? Does anyone know of another mechanism or algorithm?
If CSS is only modified in development and never in production, should not it be better to evaluate a hash for the set of CSS file names to load, eliminating content evaluation?