Question

What is a good way do design a web app with Play, which provides graceful degradation? I am working on a client application, which uses Ajax to grab some partial views, and then with JQuery, to put them in place into the DOM.

To support SEO and graceful degradation, I should either make a duplicate controller method, which renders the partial view as part of the whole page (header and footer included).So when I make a call with Jquery, it will call "item/12345/partial", it will bring only the partial view but when a user goes to "item/12345" it should show the entire page, with the partial already stuck in.

The second option is to avoid the second controller method, and always return the full page content (header,javascripts, styles,partial, and footer). When invoked with JQuery, the callback method will simply strip only the necessary HTML and fit it into the DOM. Of course, this means that really the same amount of content will always be returned from the server, so it really reduces the advantages of using AJAX in the first place.

Which one would you recommend?

Was it helpful?

Solution

Second option does not look very good for me. What we use on our project is that we have base template that is extended by ajax parts and these parts have something like this to not load rest of the template on ajax request:

#{ifnot request.ajax}
    #{extends 'search-main.html' /}
#{/ifnot}

and search-main.html has #{doLayout /} in place where ajax section should occur if full page is going to be rendered (non ajax request). Value in request.ajax will be set by Play, so you don't have to figure it out yourself.

About duplicated controllers: you should be able to map one controller to many urls if needed. Just add them to routes file. But it is not required in our approach.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top