开发者

Prevent unnecessary HTTP requests for iPhone version of website

I have a website. It uses jQuery, a few plugins, Cufon, etc to spice things up a little, mostly visually.开发者_Go百科

The iPhone version does not need any of these files.

Can I, without resorting to subdomains, prevent the iPhone from loading these scripts?

<script src="js/jquery-1.4.min.js" type="text/javascript"></script>
<script src="js/browsersupport.js" type="text/javascript"></script>
<script src="js/jquery.easing.custom.js" type="text/javascript"></script>
<script src="js/jquery.color.custom.js" type="text/javascript"></script>
<script src="js/jquery.sound.js" type="text/javascript"></script>

<script src="fonts/cufon.js" type="text/javascript"></script>
<script src="fonts/trgo.font.js" type="text/javascript"></script>

Edit:

Using a library like this one: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

How would I go on to detect iPhone?

Browser::isBrowser('iPhone');

Returns

Fatal error: Using $this when not in object context


If the user agent indicates it's an iPhone, don't load them.

Update:

According to the class you referenced, this is how it should accomplish your check - I say should simply because I can see that some users commented that this wasn't reliable for them on the blog you linked:

$browser = new Browser();
$jQuery = ($browser->getBrowser() == Browser::PLATFORM_IPHONE) ? false : true ;

See Also:

  • iPhone User Agent (StackOverflow)


Why do you not need them?

I am very suspicious because a number of sites try to present an "optmizied" iPhone version of a site.

Yet there is nothing I hate more than not being allowed to see the FULL site. The iPhone is a device with a real browser, please do NOT dumb-down your site so that it's almost worthless to iPhone users.

If you are calling web pages from within an iPhone app to get content, those js files would not be loaded (unless you are using a web view).


Browser detection will, without any doubt whatsoever, come back to strangle you in the future. Imagine that Apple launches a new iPhone that supports all this stuff, but then you have yet more options to choose from? What about a competitor platform that pretends to be an iPhone? What about any of the billion other options that could occur..? You see the problem.

As Kendall mentions here, the better thing to do is let the user choose which site to see. I know its cool to do it automatically, but its not very maintainable, and annoying for the user. Things like language detection are different, serving a totally different version of the site is not cool for some arbitrary and very unreliable variable that could or could not be present, or could or could not be true. Look up user agent strings for IE, Firefox, Opera, Safari, and you'll start to see what's going on..

There's a pretty entertaining section in PPK's book on javascript about this, but his browser detection script might be handy if you decide to go this route (please dont!)

Browser Detection with Javascript

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜