-1

I have been working on a blog application with Codeigniter 3.1.8 and AngularJS v1.7.8. It is intended to be versatile and easy to use.

The Dashboard of the application is "pure" Codeigniter, with Models, Controllers, and views, while the fronted is made up of JSONs managed and displayed by AngularJS.

I operated this clear separation between back-end and front-end in order to enable "theming". See a demo HERE.

There are several problems with using AngularJS:

  • no server-side rendering (causing SEO issues);
  • anyone accessing the website has to go through index.html (accessing any other URL directly gives a 404 error);
  • The contents of he <title> tag does not change with the view;

Replacing AngularJS with a template engine (EJS) crossed my mind but I feared I would have to run 2 servers: an Apache one and a Node.js one.

What is a viable alternative to AngularJS that would allow me to keep the application's backend and API?

3
  • The question's body is fine, it is specific and focussed (it might be interpreted as a request for 3rd party tools, which is off-topic here - but personally I would not be so strict on that in this case). However, the title was horrible, asking for the "best" approach always attracts close-votes and downvotes. I took the freedom to fix this, please check if that's ok.
    – Doc Brown
    CommentedAug 20, 2020 at 13:18
  • Thanks for the edit. However, I already have a solution, only it is not so good. So, I don't know why the question was down-voted.CommentedAug 20, 2020 at 15:58
  • As I wrote, requests for 3rd party tools are off-topic, and the question already four close votes for exactly that reason. That's most probably the reason for the downvotes, too. However, in this case the question does not look for me like one asking for a particular tool, a solution could be also one using the existing tools differently, introducing a general class of tools, or making adaptions to the architecture. That kind of questions are IMHO ok (but I am sure other parts of the community will think differently about this).
    – Doc Brown
    CommentedAug 20, 2020 at 16:09

2 Answers 2

3
+50

AngularJS has support for server-side rendering by using a Node.js server, see their documentation on it: https://angular.io/guide/universal.

This guide describes Angular Universal, a technology that renders Angular applications on the server.

A normal Angular application executes in the browser, rendering pages in the DOM in response to user actions. Angular Universal executes on the server, generating static application pages that later get bootstrapped on the client. This means that the application generally renders more quickly, giving users a chance to view the application layout before it becomes fully interactive.

[...]

You can easily prepare an app for server-side rendering using the Angular CLI. The CLI schematic @nguniversal/express-engine performs the required steps, as described below.

3
  • This is for a much newer version of Angular than what OP is using (AngularJS is specifically 1.x). I don't think there was ever an official solution for AngularJS, and with end-of-life on the horizon I doubt there ever will be.CommentedAug 20, 2020 at 15:26
  • What about a template engine like EJS or Smarty, in what conditions can it be used with a PHP API?CommentedAug 20, 2020 at 15:59
  • EJS depends on having a Javascript implementation running, you have to use it via Node.JS, in the browser or by generating the files statically (ie saving the .html files and serving those). You can use smarty via apache's PHP integration (mod_php, etc.), or you can use PHP itself as a templating language.CommentedAug 21, 2020 at 16:09
0

You will want to move to a newer framework as AngularJS 1.7 is going end of life next year. Since you are going to have work to do there, whether you go with Angular or another JS framework doesn't matter. You are probably going to have a lot of work anyway.

It is wrong that Javascript rendered sites have drawbacks when considering SEO. Ahrefs did some research on it https://ahrefs.com/blog/javascript-seo/

But there are some gotchas that you need to consider like

My personal preference would be to go with a newer framework like Angular 10, React, or VueJS and don't bother with server-side rendering unless you have other reasons than SEO.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.