Generated images not cacheable by browser
krasmussen - July 21, 2009 - 21:37
| Project: | Textimage |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
All images generated by Textimage have either disabled cache control or an expiry date in the past in their headers. This is a major annoyance on a heavy site that requires all of its images to load relatively fast or be preloaded in order for it to show correctly. See the images in the dark grey box on http://sf-viborg.dk as an example (in Firefox, check out Page info -> Media as well).
I don't know if http://www.gaiaonline.com/forum/computers-technology/php-cache-control-w... could be of any help.

#1
I can't entirely confirm, but my guess is the way that you are calling the textimages, which is an insecure and partially deprecated method.
My personal site (http://stuar.tc/lark) uses the correct theme('textimage_image') method and there are no cache issues.
Admittedly it is easier to do things the old insecure way, but it is not advised.
I will look into this further and see if I can confirm it.
Cheers,
Deciphered.
#2
As a side note, it doesn't appear that any of your textimages are even loading, which implies that you're using the old semi-deprecated method but haven't turned on the anonymous permission to generate textimages in that form.
I strongly suggest using theme('textimage') in your theme to generate textimages.
Cheers,
Deciphered.
#3
I chose the URL method because the images are backgrounds defined in the CSS (for SEO reasons). There is no way to do that with theme('textimage'), is there?
I can see that the images on your page cache just fine. I don't think it's a permissions problem, though, anonymous users are allowed to generate textimages. And I don't really understand that you're saying that they're not loading at all?
#4
You can use the theme('textimage_image') method with css, but you need to use a little bit of trickery. It might be best for me to writeup a HOWTO guide for that.
What I meant about the not loading is that when I go to your website, looking at the Net panel of Firebug, I get a bunch of results that are clearly textimages, some using the old url method (http://sf-viborg.dk/sites/default/files/textimage/footer-li/Psykiatri.png) with a 302 response and some using the new theme() method (http://sf-viborg.dk/en/sites/default/files/textimage/2/12451963685565.png) with a 200 response, but none of them contain any data, and going to the urls just gives me what I assume is the 404 page.
So evidently there is something definitely not right, which may or may not be a Textimage issue.
Attached is an example of what I see in the dark grey box, which is clearly missing the textimage quote.
#5
Ah - it seems that the reason for that is that you (or your browser?) is trying to access the english version of the site at /en/, which confuses textimage (ie. nothing at http://sf-viborg.dk/en/sites/default/files/textimage/2/12451963685565.png but then try http://sf-viborg.dk/sites/default/files/textimage/2/12451963685565.png). It's only activated because I prefer to have the admin interface in English (none of the content is translated to English) - does Drupal automatically choose the users' own browser languages on its sites?
I'd really love to see that howto - it would be great if you could find the time to write it.
#6
Ok, for i18n issue, can you please re-open the following issue, something that I opened and closed ages ago as I was unable to reproduce the issue, so any information on your setup would be helpful to.
#371753: i18n support
As for this issue, I checked the link you just provided which is the suggested method, and it proves that it isn't related to how the textimage is invoked. However, as you saw on my own personal site the issue was not present.
My guess is that the issue is actually related to your server configuration, not Textimage at all. To back this up, heres another one of your sites images, http://sf-viborg.dk/sites/all/themes/sfviborg/images/top.png, not generated by Textimage but still has 'max-age=0' set.
Marking this issue as closed, though if you do find the exact culprit, would appreciate a note to let me know and anyone else who is also experiencing this issue.
Cheers,
Deciphered.
#7
Will do.
All of the textimages on my site are invoked through the URL method, so I'm not sure why you would think that this was generated using the suggested method?
True, but top.png caches fine here despite the 'max-age=0'. In Firefox, check out Page Info -> Media. top.png appears normally, but all textimages are marked with grey and italics and are "not cached". So I guess it's some other setting that's keeping them from being cached?
#8
As I'm still not able to reproduce the issue on your page it does make it difficult to confirm, but with what you say, it may still be related to the method of calling the Textimage, and if so then the CSS -> theme() trick may not work either. This is all an assumption, but I'm guessing that because the url based call (http://sf-viborg.dk/sites/default/files/textimage/quote/%22Vi%20skal%20h...) actually points to the file (http://sf-viborg.dk/sites/default/files/textimage/3/12471611572400.png) the browser is picking it up as a 302 redirect and not caching the original file.
But, it may be caching the real file, the file that it is redirecting to. Again, as I can't see a working version of your site I can't confirm that, but check the page info media screen to see if the redirected image is listed as cached.
I would actually suggest changing the way things are done to fix this issue. While you say the file is reference in CSS, it is inline css, which I assume is created by a template file or a module? You'll need to provide me with a bit more information about exactly how it is generated, but I'm guessing it's something like this:
<h2 class="candidateQuote soeren active" style="background: url('/en/sites/default/files/textimage/quote/<?php print $quote; ?>.png') no-repeat;"><?php print $quote; ?></h2>Which you would simply replace with:
<h2 class="candidateQuote soeren active" style="background: url('<?php print theme('textimage_image', 'quote', $quote, array(), 'png', '', '', array(), TRUE, FALSE); ?>') no-repeat;"><?php print $quote; ?></h2>Note the very last variable, 'FALSE', it tells the theme function to return the path of the image, not a themed image. Admittedly I don't think I've actually documented this feature anywhere, but it should hopefully do the job.
Cheers,
Deciphered.
#9
Firefox page info screenshot attached.
Edit: Oh, too late. Nevermind this post.
#10
Yes! That was exactly the case. The browser refused to cache the redirect, and I didn't need to change more than the variable name to get your code working.
Thanks once again for running such a great project - I've never seen quicker responses to bug reports in my life ;)
#11
That's great to hear, and it's good to know that the issue exists (and how to prevent it), yet another argument for people not to use the old method. I really should deprecate the method completely, but that would probably cause more problems than it's worth.
Cheers,
Deciphered.
#12
Yeah, unfortunately you've got that right. The theme('textimage_image') function doesn't care much for my non-latin characters (æøå, specifically). Check out http://sf-viborg.dk/sites/default/files/textimage/3/12483959872007.png and http://sf-viborg.dk/sites/default/files/textimage/2/12483959875750.png - they should have been "En værdig ældrepleje" and "Søren Gytz Olesen" but are "En v rdig ldrepleje" and "Słren Gytz Olesen". The URL method had no problem. Should I open a new bug for this?
#13
Yup, definitely needs a new issue for that. Actually quite shocked that this is the case as I am positive I tested with the 'æ' character in the latest versions.
But I won't go into anything further in the issue.
#14
Fixed it by doing a utf8_encode() on the input. I don't know if that should be incorporated into the module?
Edit: It probably shouldn't. Seems that it's only needed when the input is coming from a html file (don't know if I've saved my template file in a different encoding or something).
#15
Good to hear, I actually tested it via the textimage preset preview function and the 'æ' was fine, so I'll leave it for the moment unless I get any other users having issues with it.
On a side note, that change also fixed the i18n issue, as I had suspected it might, hence the not to myself in #371753: i18n support.
Cheers,
Deciphered.