I’m about to start developing a site that will have a regular and mobile version using spring. At this point I need to make a decision on how to approach this. I foresee two options:
-
Independent sites on the same server. Develop an independent set of controllers and views for each of the sites. Trying to reuse the controllers as much as possible.
-
Intermingled sites. Develop content aware controllers that would send to different views depending on the type of device. Controllers send to different views depending on the device.
Option 1 seems more practical, but I’m afraid I’m going to end up with a lot of controller repetition. Also I would need to separate the site into http://something.com/ and http://something.com/m as the base for the mobile version.
Option 2 seems that it will turn unmanageable very soon, since changes in the regular version will have impact on the mobile one. Nevertheless it will have much more code reuse.
How would you approach this?
Option 2 always seems tempting, but in my experience it turns out to be impractical. Invariably, for anything more than trivial sites the page flow becomes different between full-fat and mobile versions, with data different data being rendered. It becomes more than just a different skin.
My advice to is to make a strong effort to identifying the common business logic, and put those into general code. Keep the controllers as thin as you can, but by having desktop- and mobile-specific controllers you can keep them focussed. Yes, there will be some duplication, but hopefully it can be minimised.
Define the common logic as beans in the webapp-level
/WEB-INF/applicationContext.xmlbeans file. Then define a separateDispatcherServletfor each site, containing the specific controllers, sharing the common beans.