While trying to optimize site for mobile devices you have to add viewport meta tag:
1 2 |
|
You can add additional CSS file that will be used on mobile device only. To achieve this just add CSS media type. In Android developer’s guide at http://developer.android.com/guide/webapps/targeting.html it suggests to target device DPI value like:
1 2 |
|
It works fine, but Google Chrome on desktop PC also loads this CSS file.
There is another solution to target mobile devices (both Android, iPhone, Blackberry): to specify maximal width of the screen like:
1 2 |
|
The problem is that Android (at least 2.3 I’ve tested) recognizes this media type only after page reloading (refreshing) in browser. Googling the web I found the open issue.
I solved it using JavaScript:
1 2 3 4 5 6 7 |
|
I tested it on my device an it works fine, unless some little delay: the CSS file loads only after JavaScript executes. When google will fix the issue (I hope so…), there will be no delay, since original link is in the HEAD section.
Of course you have to detect mobile device using the JavaScript, I used solution suggested here: http://localstreamer.posterous.com/javascript-code-snippet-how-to-detect-all-mob