Forum Moderators: phranque

Message Too Old, No Replies

Expires headers - how to without apache/.htaccess?

         

diddly

2:09 pm on Feb 15, 2015 (gmt 0)

10+ Year Member



Testing my website with Yslow, it is missing expires information for all additional media: css and images (it seems the php parser is adding some default values to the generated html, but i'd like to modify that, too).

(Yslow also complains about Etags, but i haven't even tackled that one yet.)

Is there a way to add expires and/or caching directives directly/manually?

i did some searching, but most articles go straight to apache's expires module, which does not work on this server (and there's nothing i can do about this server's configuration).
or they are not suitable for a noob like me, because they skip a lot of basic and essential info.

lucy24

8:52 pm on Feb 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Let's start by hashing out the apache aspect of the problem (your longer post next door [webmasterworld.com]). HTML is a last resort.

diddly

6:45 am on Feb 25, 2015 (gmt 0)

10+ Year Member



now that we hashed out the .htaccess aspect of this - fruitlessly [webmasterworld.com] - I'm coming back to this question.

Is it possible to define headers and actually send them, when the according apache module is not active?

If so, how can I achieve that?
I think i understand how i can achieve that for the actual html document (there's a php function header() [php.net]) - but how can I achieve it for secondary content like images, css, fonts? Afaiu, the headers() function only applies to the document from which it is called?

phranque

1:15 pm on Feb 25, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can use the <meta> element with the http-equiv attribute value set to "Expires", "Cache-Control", etc:
http://www.w3.org/wiki/HTML/Elements/meta [w3.org]

lucy24

6:28 pm on Feb 25, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you can use the <meta> element

Yah, but what about non-html content? Will it inherit the expiration settings of the html? Generally you'd want non-page content-- especially images, which might be replaced but will rarely change-- to have a longer caching time.

The long-term fix may be to change hosts, because you should absolutely be able to set your own expiration/caching times.

diddly

8:30 pm on Feb 25, 2015 (gmt 0)

10+ Year Member



ah thanks, the w3 wiki is definitely much better than the stone-old text-only documents i found...

@lucy24: exactly. what about non-html content.
i saw a php script [stackoverflow.com] that would actually generate a jpg and attach a header with proper expires, but i just don't see how i could apply that to existing pictures.

...and while i basically also agree about the long-term fix, i doubt it will happen aytime soon. my host is a friend, my website is a hobby...