Tool to create pre-compressed [Brotli] files

I am trying to generate pre-compressed brotli files in designated directories… Whatever html, css and js files are there have to be compressed to brotli.

I found a rust tool here – https://github.com/neosmart/static-compress

Besides this, there’s also an option within W3TC Wordpress plugin. However, despite brotli PHP module being loaded and available, W3TC is not creating either gzip or brotli files.

I used to depend on on-the-fly compression, but that option is no longer there.

Does anyone have any suggestions on what can be used to create pre-compressed brotli files? I thought of creating a bash script and having it run every 6 hours or so, but then, I realized that it might not be as simple as it seems, as there are cases where the original file may change, and there might already be an .br file in the folder belonging to a previous version of the original file (source file) and so on.

Looks like there’s no Wordpress plugin other than W3TC to do this either, and W3TC seems to be buggy on this aspect [I have enabled Brotli compression in Browser Cache section and also enabled preload, but it's been 12 hours and not even a single cached file has a corresponding br or gz version in the cache directory].

Has anyone taken a crack at this problem? Anything anyone would recommend?


lsyncd is a tool that watches designated directories for changes in files. If it detects a change, it can run any command.

So, one can set it up to watch your HTML directory and run brotli on the file every time it changes.

It requires some LUA programming to actually implement the functionality.

inotify-tools could be another usable tool for the purpose.

Most reliable way to do this is to have a proper deployment process for your files. Deployment process takes files from your code repository and then performs any needed operations like compression. After that it copies files to the server. Setting this up requires more effort than using the inotify-based solutions above. However, it allows most flexibility to automate things during deployment.