Search code examples
phpandroidioshtmlhtml5-appcache

Can I target specific browsers/devices with the Manifest or Appcache file or just exclude the appcache from Desktop browsers?


Essentially I would like to be able to use an appcache file on my site but only for mobile devices, to enable those devices to view the website/webapp I am developing offline, however desktops/laptops often have access to the internet and I would rather these view the site as is, with no manifest/caching etc..

I am aware user agent sniffing is at best unreliable although can provide some good results, if this could be avoided it would be best.

The site/webapp I am developing is built in HTML/CSS/JS/PHP and uses responsive layouts to serve the same pages of the site to each device with customised views/layouts depending on the devices width (using css media queries).

Thanks for any help in advance, all my searches for this specifically have proved unfruitful :(

Update

After Robertc's comments below I would like to clarify that it is Desktop Browsers (ie the very same browsers that are used on laptops) that I would like to exclude any caching from via appcache/manifest file... This is a requirement from client and also from me as programmatically it seems easier to target desktops and laptops together as they are using same software/OS...

More specifically my webapp needs to support caching via appcache/manifest on iOS, Android & Blackberry (although it would be nice to have all tablets/smartphones) so maybe the question is how to find one of these devices and include the appcache reference, however this looks like it is leading down the path of user agent sniffing which I was hoping to avoid...


Solution

  • Because the browser does check the Appcache.manifast before everything else happens, you have to do an additional serverside detection. You cannot load the appcache.manifest by javascript.

    Make a Serverside detection on the Useragent and deliver the HTML with manifest if you get a request from iphone, ipad, android etc. and without manifest in the other cases.

    User Agent checking is the best approach. You deliver your site for people who doesn't fake there User Agent.

    User agent test with php for mobile devices (just add your devices you need):