Skip to content

Conversation

@gassan
Copy link

@gassan gassan commented Apr 16, 2019

md5 hash of static files containing @include another static, url(static_image.png), etc can be changed multiple times:

Original -> A -> B -> C.
Old version compressed file A based on a hash of Original, so web server tried to get .hash-C.ext.gz file, could not find it and generated it on fly from hash-C.ext

default STATIC_COMPRESS_MIN_SIZE_KB changed to 0. nginx server always tries to get .gz file regardless of the size

…ic_image.png), etc can be changed multiple times:

Original -> A -> B -> C.
Old version compressed file A based on a hash of Original, so web server should generate gz files from C on fly.
Copy link
Owner

@whs whs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are more than one changes in this PR. Please consider splitting the PR.

self.compress_methods = getattr(settings, "STATIC_COMPRESS_METHODS", DEFAULT_METHODS)
self.keep_original = getattr(settings, "STATIC_COMPRESS_KEEP_ORIGINAL", True)
self.minimum_kb = getattr(settings, "STATIC_COMPRESS_MIN_SIZE_KB", 30)
self.minimum_kb = getattr(settings, "STATIC_COMPRESS_MIN_SIZE_KB", 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not ok with changing this. Compressing everything make building slower and it is not always smaller.

If you want deterministic file hash from your web server, either fix the web server or change the library's configuration value.

Copy link
Author

@gassan gassan Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question here is. should I make it once or let my web server do it for me multiple times.
look at output of:
# strace -p $NGINX_WORKER_PID 2>&1 | grep .gz
On this art of errors generates nginx .gz file on fly if gzip = on; is set.
if not, so error 404 will be sent.

Edit: precondition for e404 here gzip_static = on;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can either turns gzip off in your web server, or set STATIC_COMPRESS_MIN_SIZE_KB=0 in your site's configuration.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, its right

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but with >0 not to exclude that it comes to the 404 error with default settings. so consider the user your module faulty and uninstall it:)

Copy link
Owner

@whs whs Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you hardcoding .gz/.br in your page?

The installation guide recommends that your web server should be configured to serve precompressed files.

Copy link
Author

@gassan gassan Apr 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I am using CompressedManifestStaticFilesStorage und yes gzip_static is on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If gzip is off, i get 404 because requested file is C.hashC.css but exists as gzipped only A.OriginalHash.css
A, B are intermediate und C final versions of a certain file.

if dry_run:
return

files = OrderedDict()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear why this file has to be changed, based on the pull request's description.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at super() class. with --dry-run no files are generated

generator = iter((f, f, False) for f in paths)

for file, hashed_file, processed in generator:
files[file] = hashed_file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not exactly clear what this is doing. Consider adding commenting.

I'm guessing that it is to not process files that are not emitted by super class. If possible please consider splitting this to another PR so we can review this easier.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure here.
a super class must not have a post_process() method implemented. so you have to take in this case the whole fileset, that have not been post_processed


for name in paths.keys():
if not self._is_file_allowed(name):
if not (name in files and self._is_file_allowed(name)):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if name not in files or not self._is_file_allowed(name)

Copy link
Author

@gassan gassan Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a matter of taste and legibility :)

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

Successfully merging this pull request may close these issues.

2 participants