Both HTML and CSS provide ways of doing this without JavaScript.
As per the above link, you can specify different stylesheets for different devices using:
<link rel="stylesheet" href="screen.css" media="screen"/>
<link rel="stylesheet" href="handheld.css" media="handheld"/>
Or if you want to use a single stylesheet:
@media screen { /* rules for computer screens */ }
@media handheld { /* rules for handheld devices */ }
or with @import
:
@import "screen.css" screen; @import "handheld.css" handheld;
A mobile portal is probably the best option since mobile users likely have different surfing patterns and different uses (are looking for different info, using different features, etc.) for the site. But if you want to maintain a single portal, then just make use of what is already provided in the HTML and CSS specifications.
Note:
If you're adhering to the MVC design pattern, then it should be relatively easy to build a single application and render different Views to the user depending on whether they access the site via http://myapp.com
or http://mobile.myapp.com
. This means your Controllers and Models stay the same, and you just need to create separate views for the parts of the app that mobile users will access. The same technique would be used for generating RSS feeds or implementing a REST API.
Edit:
The issue of newer non-compliant mobile browsers is a bit tricky. On the one hand, the reason they render both spreadsheets is because they felt that web devs were dumbing/stripping down their sites too much for mobile users (for good reason, as many older, less advanced mobile browsers are still used), and mobile browsers are catching up to desktop browsers in rendering capabilities. But OTOH, the resolution difference and screen size is still an issue.
So what I would do is use 2 sets of spreadsheets, but design for 3 sets of users:
- desktop users: loads
screen.css
only
- new mobile users: loads
screen.css
and handheld.css
- old mobile users: loads
handheld.css
only
The cascading nature of CSS means that, with some careful testing, you should be able to cater to all 3 demographics. There may be some browser-detection tricks that you could apply, but that doesn't seem necessary.