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

Support images with query strings on them #34

Closed
benhutton opened this issue Oct 11, 2017 · 6 comments
Closed

Support images with query strings on them #34

benhutton opened this issue Oct 11, 2017 · 6 comments

Comments

@benhutton
Copy link

Our image urls already end with a cache busting timestamp for a query string.

Because of https://github.com/imgix/imgix-rb/blob/master/lib/imgix/path.rb#L91, the imgix query string is not being properly appended to an existing query string. It assumes there is no query string.

Our image paths look something like /path/to/image.jpg?t=12345567

Currently, we get something like /path/to/image.jpg?t=12345567?w=500&h=300

Too many question marks! It should be /path/to/image.jpg?t=12345567&w=500&h=300

@gregpardo
Copy link

We have this same setup with cloudfront. You could probably do something like this... Check if the string contains more than one '?'. If it does replace any following with '&'

@benhutton
Copy link
Author

sure... we are doing that too. Ideally this code would be smart enough that we wouldn't have to though!

@axelson
Copy link

axelson commented Jan 11, 2018

@benhutton what are you doing to work around this? I'm having trouble using a cache busting timestamp

@benhutton
Copy link
Author

@axelson I've moved away from timestamps to asset fingerprinting based based on an md5 hash of the file contents. So, your filename looks like filename-hash.ext. Here's an actual URL we're using: https://dg.imgix.net/waiting-for-god-to-text-back-vrcfown9-en/landscape/waiting-for-god-to-text-back-vrcfown9-1d26513c3498499dd96683b1dd770609.jpg

@axelson
Copy link

axelson commented Jan 11, 2018

Ah, ok. That's a bit harder for us since our server never touches the files, they go straight to s3. As far as I can tell it is actually impossible to use query parameters to bust Imgix's cache. At least I only need this as a temporary transition and Imgix's url purging endpoint seems to be working well.

@sherwinski
Copy link
Contributor

For anyone who might still be wondering about this issue/finding this over a year later, there are a few things I want to mention.
Although this might not have been the case when this issue was originally opened, in this project's latest release you can add the cache busting parameter in the following way:

client.path("/path/to/image.jpg").to_url({t:12345567})
# .../path/to/image.jpg?ixlib=rb-3.0.0&t=12345567

path() should only be passed the image path (everything before ?) while to_url() can be used to append any number of query parameters. This would avoid the double ? scenario, which can cause unexpected behavior on the imgix backend. Again, this behavior might not have always been the case. I also want to note that sometime in the future we will implement better path validation to avoid these types of scenarios.

Closing this issue now, but feel free to comment back with any questions.

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

4 participants