Django pipeline Cache Busting is not Updating Cached File/Hash
Asked Answered
B

1

25

Basically, the hash on the cache busting file is not updating.

class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
     pass

PIPELINE_JS = {
 'main.js': {
    'output_filename': 'js/main.min.js',
    'source_filenames': [
        'js/external/underscore.js',
        'js/external/backbone-1.0.0.js',
        'js/external/bootstrap-2.2.0.min.js',
    ]
  }
}

When I first ran the collectstatic command, it properly created a cache busting file named "main.min.d25bdd71759d.js

Now when I run the command, however, it is failing to overwrite that cached file (and update the hash) during the post process phase.

It keeps updating "main.min.js", such that main.min.js is current with my filesystem. A new cached file, however is not created. It keeps the same old hash even though the underlying main.min.js file has changed.

When I manually delete the cached file on AWS, I get the following message from running collectstatic with verbosity set to 3:

Post-processed 'js/main.min.js' as 'js/main.min.d25bdd71759d.js

settings.DEBUG is set to False

Why won't the hash update?

Boote answered 29/7, 2013 at 17:41 Comment(4)
Please, show related settings: PIPELINE_ENABLED, STATICFILES_STORAGE, STATICFILES_FINDERSBehindhand
Can you make sure that the main.min.js is different from the previous one? The hash won't change if there aren't any changes in the file itself. It looks like you are only including libraries in main.js, which you shouldn't be editing, so that is why I am asking.Remillard
You mentioned you user AWS storage(I suppose boto). Can you check if problem still reproduces if you pipeline static to local folder(not to AWS). I suppose it is most probably boto issue.Autrey
Is your timezone set to something west of UTC? That can cause problems with collectstatic and S3BotoStorage.Malapropos
K
3

Try using the manifest storage instead:

class S3PipelineManifestStorage(PipelineMixin, ManifestFilesMixin, S3BotoStorage):
    pass

According to the django docs here https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#cachedstaticfilesstorage it's not recommended to use CachedStaticFilesStorage.

Your files names for your static files are probably getting cached. So use the manifest one.

CachedStaticFilesStorage isn’t recommended – in almost all cases ManifestStaticFilesStorage is a better choice. There are several performance penalties when using CachedStaticFilesStorage since a cache miss requires hashing files at runtime. Remote file storage require several round-trips to hash a file on a cache miss, as several file accesses are required to ensure that the file hash is correct in the case of nested file paths.

Note this is also documented at django-pipelines http://django-pipeline.readthedocs.io/en/latest/storages.html#using-with-other-storages

Kweichow answered 2/1, 2018 at 16:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.