Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assetic writer with checksum? #857

Open
featheredtoast opened this issue Sep 21, 2017 · 0 comments
Open

assetic writer with checksum? #857

featheredtoast opened this issue Sep 21, 2017 · 0 comments

Comments

@featheredtoast
Copy link

Would you be up to add an md5 checksum to the AsseticWriter to prevent files from modifying with the same data? This would be great for development pipelines, as it'd prevent etags from being changed, and thus be able to more accurately predict when resources change.

My use case comes in from using assetic + live.js for development environments, in which I only want css to recompute and emit a new etag, while all the javascripts prevent a reload of the page.

Something like the following modifications in the AssetWriter:

  protected static function write($path, $contents)
    {
        if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {
            throw new \RuntimeException('Unable to create directory '.$dir);
        }

        if(file_exists($path) && md5($contents) == md5(@file_get_contents($path)))
        {
            echo "Not modified: ".$path."\n";
            return;
        }

        if (false === @file_put_contents($path, $contents)) {
            throw new \RuntimeException('Unable to write file '.$path);
        }
    }

Due to the way the variables are private currently, there is no good way of extending this class, short of re-implementing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant