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

Browser not caching generated images (no 304) #185

Closed
YannikFirre opened this issue Mar 29, 2017 · 3 comments
Closed

Browser not caching generated images (no 304) #185

YannikFirre opened this issue Mar 29, 2017 · 3 comments

Comments

@YannikFirre
Copy link

Hello,

in reference at this issue : #20

The issue seems to be in v1 ? I don't found the header if-modified-since.

@cdowdy
Copy link

cdowdy commented Mar 29, 2017

@InfinityWebMe try passing in your request to your response factory as seen here for laravel

laravel example:

use League\Glide\ServerFactory;
use League\Glide\Responses\LaravelResponseFactory;

$server = ServerFactory::create([
    'response' => new LaravelResponseFactory(app('request'))
]);  

or for symfony

use League\Glide\ServerFactory;
use League\Glide\Responses\SymfonyResponseFactory;  

$server = ServerFactory::create([  
  'response' => new SymfonyResponseFactory($app['request']),  
]);  

That "should" do it .... maybe haha.

@YannikFirre
Copy link
Author

@cdowdy
Hello, I don't use common framework on this project. Why is not by default ?
Thanks to the reply :)

@reinink
Copy link
Contributor

reinink commented Mar 30, 2017

It's not done by default in the outputImage() method largely because that isn't really the ideal way of using Glide. We generally recommend working with proper response objects.

Even if you're not using a framework, I'd recommend installing the HttpFoundation package. This allows you to optionally pass in a request object, which will be used to figure out the If-Modified-Since header.

Completely untested, this would look something like this:

use League\Glide\Responses\SymfonyResponseFactory;
use League\Glide\ServerFactory;
use Symfony\Component\HttpFoundation\Request;

// Setup Glide server
$server = ServerFactory::create([
    'source' => 'path/to/source/folder',
    'cache' => 'path/to/cache/folder',
    'response' => new SymfonyResponseFactory(
        Request::createFromGlobals()
    )
]);

// Output image
$server->getImageResponse('users/1.jpg', ['w' => 300, 'h' => 400])->send();

Remember to install the league/glide-symfony package:

composer require league/glide-symfony

And for what it's worth, this will be baked into version 2.0, since that will copy with HttpFoundation (and a PSR-7) implementation by default.

Good luck!

@reinink reinink closed this as completed Mar 30, 2017
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

3 participants