beans compiled assets update


When a change is made to the local css or js files included by Beans' asset compiler, the asset are not recompiled automatically (when not in development mode).

When I "Flush assets cache", the compiled files get removed and re-generated on the next request to the website, but the NAME of the asset file stays the same, thus, the client's browser does not fetch a new version.

How should I go about this? Is that a known bug or what?

Thanks!


I checked the source code and it looks like there is currently no way around this.

So I created this patch which allow manually overriding the asset cache filename using a filter:

--- ../tm-beans/lib/api/compiler/class-compiler.php.dist        2018-02-21 11:05:16.726866513 -0500
+++ ../tm-beans/lib/api/compiler/class-compiler.php     2018-02-21 13:48:57.960768825 -0500
@@ -157,7 +157,8 @@

                // Stop here and return filename if not in dev mode or if not using filesystem.
                if ( ! _beans_is_compiler_dev_mode() || ! @is_dir( $this->dir ) ) {
-                       return $this->compiler['filename'] = $hash . '.' . $this->get_extension();
+                       $this->compiler['filename'] = $hash . '.' . $this->get_extension();
+                       return $this->compiler['filename'] = apply_filters( 'beans_compiler_filename_' . $this->compiler['id'], $this->compiler['filename'] );
                }

                $fragments_filemtime = array();

It can be used like this from the child template:

$id = 'uikit';
add_filter( 'beans_compiler_filename_beans', function($filename) {
    return "{$filename}?v1.0.1";
});

There is also a simpler solution... basic wordpress filter hook:

add_filter( 'style_loader_src', function($src, $handle) {
    if ('beans' === $handle)
        return "{$src}?v=1.0.3";
    else
       return $src;

}, 9, 2);

add_filter( 'script_loader_src', function($src, $handle) {
    if ('beans' === $handle)
        return "{$src}?v=1.0.1";
    else
       return $src;
}, 9, 2);

Write a reply

Login or register to write a reply, it's free!