Advertisement

HTTP_ACCEPT not correct

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
MrDog
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Tue Sep 29, 2009 10:34 pm

HTTP_ACCEPT not correct

Post by MrDog » Fri Jan 10, 2025 11:50 pm

Not sure if this is a Joomla issue or PHP?
When serving images we check to see if the browser support webp using

if (strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' )

We are fairly sure that this used to work, but my fellow webmaster recently checked and we were have only been serving JPEG images for quite some time.

I checked the header sent with the HTTP request (and same on Chrome and FF) and it had

Accept: image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5

which seems OK. However if I log the $_SERVER['HTTP_ACCEPT'] before the above code it shows:

text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Which explains why the webp is not being server. This was on our production server.

So I tried on my development (WIndows) system and got different results:

The header was:

Accept image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8

but my log now shows

text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7

which means the test passes. Now I realise that all browsers have supported webp for around 4 years so the test is not really needed in any case, but it certainly seems strange!

Advertisement
User avatar
ceford
Joomla! Hero
Joomla! Hero
Posts: 2987
Joined: Mon Feb 24, 2014 10:38 pm
Location: Edinburgh, Scotland
Contact:

Re: HTTP_ACCEPT not correct

Post by ceford » Sat Jan 11, 2025 6:03 pm

You might consider using a responsive images plugin. This one generates a suite of images in webp and jpg or png format on the fly and replaces img tags with picture tags: https://extensions.joomla.org/extension ... ve-images/ - the browser then uses whichever is most appropriate for its capabilities.

MrDog
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Tue Sep 29, 2009 10:34 pm

Re: HTTP_ACCEPT not correct

Post by MrDog » Sat Jan 11, 2025 7:46 pm

That is basically what I have already - and it used to work by detecting if the browser supported webp using the HTTP_ACCEPT. The simple solution given that all browsers support webp now is just to serve webp, but I am intrigued as to why my code does not get the right value.

Advertisement

Post Reply

Return to “Joomla! 4.x Coding”