Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


timmmay

20858 posts

Uber Geek
+1 received by user: 5350

Trusted
Lifetime subscriber

#171346 14-Apr-2015 19:39
Send private message

Google has a big mobile push on at the moment. If your website isn't fast and highly optimised for mobile devices you get kicked down the rankings from April 21st apparently. Tester here.

I have a wordpress website with responsive design css, but the images served to mobiles are still full size. I tried dynamically resizing images based on the client using .htaccess and a pretty cool php adaptive images script but as filenames don't change this isn't compatible with my CDN. The CDN (Cloudflare Free) is set to cache images (of course) and it caches the first image that comes back, whether it's desktop or mobile, so I'd need to turn off image caching and lose most of the advantage of the CDN. Doing it with Javascript to rewrite the page is kinda messy, and if you make substitutions apparently it can end up loading both sets of images.

I figure the cleanest way to do this is in PHP, detecting the user agent and generating/rewriting the html based on the user agent. The mobile site html can refer to smaller images, which will have to be generated somehow, in advance ideally, or cached. That means you can't cache html, but oh well. Does anyone know a good way to do this, maybe a wordpress plugin? Does anyone have any alternate suggestions?

Create new topic
freitasm
BDFL - Memuneh
80646 posts

Uber Geek
+1 received by user: 41030

Administrator
ID Verified
Trusted
Geekzone
Lifetime subscriber

  #1283215 14-Apr-2015 20:33
Send private message

Do you have the option to add a query string to the image name? You could add a querystring to the image name and configure Cloudflare to cache different querystrings - for example www.example.com/image?width=300 or www.example.com/image?width=150.




Referral links: Quic Broadband (free setup code: R587125ERQ6VE) | Samsung | AliExpress | Wise | Sharesies 

 

Support Geekzone by subscribing (browse ads-free), or making a one-off or recurring donation through PressPatron.

 




timmmay

20858 posts

Uber Geek
+1 received by user: 5350

Trusted
Lifetime subscriber

  #1283217 14-Apr-2015 20:35
Send private message

I might be able to, but query strings tend to prevent caching, which I find important for images. My server's a shared one in the US, page load times are 9 seconds natively, 2 seconds with Cloudflare.

I think I'm going to have to manually change Wordpress.

freitasm
BDFL - Memuneh
80646 posts

Uber Geek
+1 received by user: 41030

Administrator
ID Verified
Trusted
Geekzone
Lifetime subscriber

  #1283231 14-Apr-2015 20:41
Send private message

Check the Cloudflare settings - they have an option to cache at different levels, with and without querystrings.





Referral links: Quic Broadband (free setup code: R587125ERQ6VE) | Samsung | AliExpress | Wise | Sharesies 

 

Support Geekzone by subscribing (browse ads-free), or making a one-off or recurring donation through PressPatron.

 




timmmay

20858 posts

Uber Geek
+1 received by user: 5350

Trusted
Lifetime subscriber

  #1283235 14-Apr-2015 20:45
Send private message

Yep it does, I just don't trust caching anything with query strings. In wordpress they often refer to js files with abc.js?ver=123, I strip those out with a plugin and it makes performance tests faster generally. Plus I'd have to manually code that up I think. Thanks for the idea.

I also found this, which I'll give a go.

jnimmo
1098 posts

Uber Geek
+1 received by user: 255


  #1283255 14-Apr-2015 21:10
Send private message

Yeah was about to suggest looking for a WP plugin. Can do retina images for you at the same time ; file names instead of query str

timmmay

20858 posts

Uber Geek
+1 received by user: 5350

Trusted
Lifetime subscriber

  #1283275 14-Apr-2015 21:21
Send private message

I only have 800px wide images, I figure people with retina displays will be used to standard sizes anyway.

I'm looking down the path of detecting whether the viewer is on mobile using the mobble plugin, if they are somehow forcing the gallery tag to use the size="medium" parameter, which shows 400px wide images which are much smaller files. I may hard code it (hope not), hopefully someone can suggest a plugin that does it, or worst case I could probably work out how to write a wordpress plugin - I don't much like PHP though.

The Responsify WP plugin seems to do exactly what I want :)

Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.