Redirection vs $.ajax() overhead

Hello,

I’ve been wondering about the performance and overhead differences between redirecting to a page to use a controller function vs. calling the page via ajax.

While working on a ticket I’ve seen that at least in the reporting module, controller methods are called via using document.location.href = somemethodpage and letting the called method return a redirect: someotherpage , where someotherpage would normally be the same page I was actually coming from. I would assume that this creates some overhead, right? It might be negligible, but I was just wondering what the main reason for this is? To avoid cluttering the .jsp pages with script code to change elements?

@flobue, in practice a lot of the reporting module’s JSP-based UI was written 7+ years ago, when the entire OpenMRS application had no standard usage of AJAX. In other words, don’t presume that any particular existing code you come across is best-practice. (But also keep in mind that we haven’t ever had enough resources to back and refactor things that work correctly, especially if they’re admin-focused, rather than end-user focused.)

-Darius

@darius To be honest, I’m still new to such large scale web applications so when I ask such questions I’m often not very sure myself. Would you say it would be better practice to use AJAX here instead of redirections? I’m asking because it’s often not very clear when something is negligible and maybe has something else positive going for it. It was just the most obvious thought that came to my mind, but that isn’t always correct for things that happen under the hood.

Also, if I change anything, especially as a new developer here, I aim for consistency. So in this case, I would redirect as well (at least within the reporting module) to keep too many different practices from floating around. Is there any loose guideline I could follow there? Something like: Generally use the practices used in a module, or maybe even always use current best-practices if possible?

Edit: While I’m at it, is there any particular new module you would recommend to get a glimpse of the current best practice standards for me to see?

@flobue our general practice is to continually improve. It is only that some times we do not have enough resources to do all that we would have wanted. Therefore, whenever you see something and think of a better alternative, do not fear to come and post about it, however widely used the old practice may be.

Going forward, we recommend HTML, JavaScript, CSS and making REST calls to the server.

You could take a look at: https://wiki.openmrs.org/pages/viewpage.action?pageId=93359610 https://wiki.openmrs.org/display/docs/Open+Web+Apps+Module https://wiki.openmrs.org/display/docs/REST+Module

@dkayiwa Thanks, so are OWAs not just mainly for those that don’t wanna bother with the Java server code, but the main way to develop modules from here on out? I’m more of a Java than a JS dev so I thought OWAs were supposed to be for those devs, who are more proficient with front-end than back-end programming. Maybe I got that wrong.

@flobue because you talked about page redirects and ajax, i thought you were a user interface guy. :slight_smile: For server side, we recommend a Java API accompanied with REST for client side access.

@dkayiwa Well yeah, in this case the ticket has to do with that. Also I sometimes had to work with web UIs, so I know some basics. But I’m really more comfortable with good old Java and without messing with UIs, that never turn out to display the way I want them :P. I see, thanks!

@flobue can you point to one example page that you’re talking about, and I can comment on it specifically?

@darius Yeah sure, for example manageScheduledReports.jsp, confirmDelete() fits my description.