iwyg / jitimage

Just In Time image manipulation (GD, Imagick, imagemagick) with integration for laravel 4
MIT License
95 stars 8 forks source link

Images not caching in browser #10

Closed alanquigley closed 10 years ago

alanquigley commented 10 years ago

HTTP/1.1 200 OK Date: Mon, 02 Dec 2013 16:17:22 GMT Server: Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips mod_bwlimited/1.4 X-Powered-By: PHP/5.4.21 Cache-Control: no-cache, public ETag: "97630a98d645cc66026101280d977913" Cache-Control: max-age=2592000 Expires: Wed, 01 Jan 2014 16:17:22 GMT X-UA-Compatible: IE=edge Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: image/jpeg

iwyg commented 10 years ago

Yes, it occurred to me that it wouldn't work for images as resource, however, they'll be cached when embedded on in a webpage.

I'll have to wrap my head around this and tweak the image response.

alanquigley commented 10 years ago

Thanks for your response, I'm not sure I fully understand the issue. Can you recommend a workaround?

iwyg commented 10 years ago

http cacheing seems to be broken for generic response types, I'll have to fix it first.

alanquigley commented 10 years ago

Just noticed something, I was looking at the image Response in Charles, seems that each one has a laravel error page attached to its bottom when viewed as raw.

iwyg commented 10 years ago

Hm, that's interesting. Does it occur on direct resource calls or just when calling multiple images on a page?

There's something else I can't get to work properly. Actually the browser requests the connection to stay alive but somehow the connection get closed, even when I explicitly set the response headers.

However, if you're able to use the xsend response type, caching will work (although not because of my implementation but because of some internal x-sendfile apache caching I guess)

iwyg commented 10 years ago

ok, got it working now. Will push a update asap.

iwyg commented 10 years ago

I've just pushed and update and http caching seems to work fine now. I'll need some more testing though. Will release a new version soon.

alanquigley commented 10 years ago

https://gist.github.com/basesignal/7768947

Thats the error page attached to the bottom of the image file, seems like it returns the image and immediately redirects.

Something else I've noticed:

AbstractFileResponse.php line 88 $this->etags never seems to get set.

Ill happily test the fix if you want, thanks:)

alanquigley commented 10 years ago

Just updated, whats happening is every second request fails

https://gist.github.com/basesignal/7769436

iwyg commented 10 years ago

to be honest, this is not very useful

iwyg commented 10 years ago

have you properly set up your environment variable in Laravel? And in the jitimage config?

alanquigley commented 10 years ago

As far as I can see everything is configured correctly.

iwyg commented 10 years ago

Hm, you probably still have an old version since etags is gone https://github.com/iwyg/jitimage/blob/master/src/Thapp/JitImage/Response/AbstractFileResponse.php#L88

alanquigley commented 10 years ago

Configuring my server to use x-sendfile, hopfully this will get it working.

Installing thapp/jitimage (dev-master 024f350) - Seems to be the most recent.

iwyg commented 10 years ago

If encountered something quite similar. If there's a large set of images, chrome wouldn't render them all. In fact, observing the ones that are not rendered there's no response at all. This happens only if cache is disabled in devtools , the first time the page is rendered, or the jjitimage cache is fresh (aka with a 200 status). It happens with all response types and file drivers. But it hasn't anything to do with Jitimage. It's a chrome thing and I don't know why. It works on every other browser I've been testing.

iwyg commented 10 years ago

Same thing with opera. Since they're also using blink now, this seems to confirm my theory.

iwyg commented 10 years ago

Ha!, nailed it!

iwyg commented 10 years ago

Can you try the latest commit?

Also please be sure your environment is set up properly in /app/bootstrap.start.php

And also clear the image cache php artisan jitimage:clearcache

e.g.


// /app/bootstrap.start.php

$env = $app->detectEnvironment(array(
    'local' => array('your-machine-name'),
    'development' => array('*.dev'),
    'production' => array('*.com'),
));

which should correspond to the environments you want't images to be cached:


// /app/config/packages/thapp/jitimage/config.php

'cache' => [
    'environments' => ['production', 'development', 'foo']
]
alanquigley commented 10 years ago

Just installed it. Same results I'm afraid, loads first time and then when it loads the second time it crashes

I've check the bootstrap variables all seem fine, clear the server cache.

alanquigley commented 10 years ago

Is the above link working on any browser for you?

alanquigley commented 10 years ago

Images loaded using the facade do seem to work!!

/jit/storage/6bbd4aa2/jit_d8c69e73937cf892.jpg

JitImage::source($person->portrait->original)->cropAndResize(333, 192, 5)

iwyg commented 10 years ago

Hm, seems to be a bug in the controller, hope this fixes it

alanquigley commented 10 years ago

Looking good!! seems like its working. That was above and beyond the call. Thanks for sorting this out.

iwyg commented 10 years ago

You're welcome :)