Choosing between Thymeleaf and Angular for a new Spring MVC project [closed]
I'm starting a new Spring Boot web application and I need to make a choice about how to implement front-end.
I'm really comfortable with Thymeleaf templating framework that I used in several projects, but I'm evaluating Angular (v2) as a possible alternative.
I'm quite new to client-side MVC frameworks and I'd like to understand if there are some guidelines to decide which option is the best for a web project.
I've read a lot of posts and tutorials about this, but they all seem to describe personal opinions or to be just coding experiments...
Are there some application requirements that objectively suggest to use a client-side approach instead of a server-side implementation?
Is it possible and effective to use both the technologies together?
Thymeleaf and AngularJS are not mutually exclusive. You can certainly use them together, depending on what you are trying to accomplish. If you are all in on writing a single-page dynamic web application, Thymeleaf is probably unnecessary.
Speaking to your question about client side frameworks vs. server-side ones, I'm an Enterprise Software Engineer, so I am not creating commercial software and my priority is less about how pretty it looks (a little Bootstrap does the trick) and more about stability, browser compatibility (even with older browsers), and maintainability. I personally avoid the single page, dynamic web applications because I find the code base more difficult to manage in non-trivial applications; a large Javascript code base can be a bear, in my opinion. Building up my pages primarily on the server side provides me with better debugging capabilities (Java is going to give you a lot of compile time help that you don't get with Javascript) and easier logging. I do use javascript (mostly just jquery) on the client side, but generally my web apps are built to degrade gracefully if the user has javascript turned off. Again, these are internal, utilitarian, applications to support the business. I don't have time to write a whole thesis on the subject and there are plenty of nuances that I'm not covering, but hopefully this is useful.
If you need your web app to act more like a mobile or desktop application, then single-page dynamic web app using a framework like AngularJS is one way to go.
The choice isn't whether to use one JavaScript library or Thymeleaf, that would be an artificial constraint you created, they are both different animals. Thymeleaf is for templating, JQuery is a client side library for making dynamic pages. It would make more sense to choose between templating libraries or choosing between JavaScript libraries, but both can go nicely together.
In general, your templating should not affect your JavaScript code, some people do template their Javascript code, but IMHO this is a terrible idea. Instead use Templating to replace tag attributes in HTML, and Javascript for making your website dynamic with whatever library you choose.
I'm not sure what you mean by
client-side approah instead of a server-side implementation
But what I see nowadays are 2 different approaches, creating Microservies VS Monolith web application. If you develop your website entirely in Thymeleaf you will not make it very reusable. Netflix, Amazon, Uber etc. all create services (sometimes called micro-services) which are reused throughout the organisation via a REST API.
If you only have a website implemented in Thymeleaf it will not be possible for another application (think mobile) to access any services created by your application, whereas if you create a REST API for your app then you can keep reusing your server back-end for when you need to make a mobile app, or another web app with similar requirements.
Of course if your services are not going to be re-used this might not matter to you and you might be very proficient in doing things a certain way albeit not being the most reusable, of course we are not always creating the next Amazon. But I still believe it is good idea to follow best practices, even if its just to get better at doing things a certain way.