Mashing up your applications
Keeping web applications separate but mashable is an interesting problem we've tried to solve here at my company.
I'm going to post the 3 ways we've tried to approach this, and hopefully I'll get some feedback.
So this is our setup (I'm keeping it simple). Here are our applications that we want to "mash up":
- The signup app
- The shopping app
- All other "parent" web sites
A brief explanation of these 3 applications:
The signup app - You must signup before you can buy our products. The signup application basically just presents the users with a form that gathers their information, a verify screen, and a success screen. From the success screen the user can select a couple of options, whether they want to go on to buy normal products OR whether they want to setup a monthly recurring order.
whichever choice you pick sends you to:
The shopping app - This application handles buying products. It simply has a "cart" page, on which you can do an ajax search and add/remove products in your cart, a Payment/Shipping page in which you decide how to pay and where you want it to go, and finally a success page where you get an order number.
At our company we decided that we wanted to write these 2 applications one time, and then reuse them over and over again in different contexts or consuming applications. So we made both applications "skinnable" by allowing you to initialize them with different css skins.
3 approaches used:
1. Iframes
This was our inital approach. This allowed a "parent" application to embed the signup or shop apps wherever they wanted.
So the parent application had a page like https://www.parent.com/shopping.html
which included an iframe that pointed at https://www.parent/com/shopApp?
The parent app was one web application deployable, and the shopApp was another web application deployable.
This approached defined a lot of interface points such as:
- "landing pages" that the signup/shop apps would redirect back to once the user was done with an operation such as "signup" or "buy products".
- Css initialization, various parent applications wanted the embedded shop/signup apps to use a different color scheme that meshed better with their look.
- initialization parameters - for both signup and shop apps we initialized those applications with parameters like "calling parent application id", products skus, or startup modes.
PROS: The shop & signup apps looked very embedded on the "parent" apps what used them.
CONS: The shop & signup apps needed to be on the same domain as the calling applications to facilitate things like iframe resizing, and cookie sharing. Domain profileration: basically we needed to purchase a secure domain for every parent app that wanted to embed shopping or signup. At our company we had at least 10+ domains and growing that wanted embedded shopping and signup.
2. Redirects
This was our 2nd approach. Basically we decided that we wanted the shop & signup apps to have their own domain and we didn't want to buy a new secure domain every time we wanted to launch a new site.
So now the parent application http://www.parent.com redirects to https://shop.parent.com.
Again the http://www.parent.com is one web application and https://shop.parent.com is another web application.
Again, interface points are required to pass between the applications such as:
https://shop.parent.com?landingPage=http://www.parent.com/doneWithOrder.html
The CON and PRO with this approach is that the shopping application is now more decoupled from the look or the parent application. One approach used to mitigate this is by using apache server side includes to include a header and footer on the child application.
i.e.
[ header ssi ]
[ main content ]
[ footer ssi ]
Where the header & footer ssi is a header that is produced by the parent application.
The advantage of this is that, if the parent application changes the look of their header or footer, the signup or shop applications do not have to be redeployed - just the parent application needs to change.
3. Pure ajax application
The last approach we are considering, is converting the signup/shop applications into pure ajax applications. This should allow for the applications again to be mashed into the parent application at any point without having to redirect.
Again, each child application basically has 3 "views".
- The signup application has: "fill out form", "verify form data", and "confirm signup".
- The shopping application has: "show cart (where you can add/remove products)", "choose payment/shipping", and "order confirmation"
To produce a "pure ajax" application, each child application (the signup & shop applications) would produce 3 elements or "views" that are hidden or shown depending on the user interaction. The views are controlled via javascript as well as are the calls back to the server such as:
"create order", "signup", "validate field", etc...
All server side interaction is done via restful web service calls.
The "parent" application pulls down the html via a javascript include.
i.e. To embed the pure ajax application it could look like this:
<script src="http://www.shop.com/shop?containerId=shopContainer"></script>
<div id="shopContainer"></div>
The javascript file loaded would automatically load the shopping application's html into the #shopContainer div. All of the other controls needed for the shopping application are loaded in the javascript file.
Note: for my purposes, the the shop.js resource is actually a java servlet that produces all of the javascript code. Of course this resource can be anything that produces the javascript.
PROS: No need for iframe resize callbacks. Everything is on the same domain, including cookies. No need to pass css initalizers since the html pulled down via ajax will get the same css applied to it.
CONS: Most big companies seem to opt for option #2, Redirects. This allows for one shopping domain and one signup domain.
Your comments on these 3 approaches are welcome.