skip to Main Content

I’m trying to get full html generated by SPA done in AngularJS.

            $.get('http://localhost:3388/' + d.response.path, function (d) {
                $('#templateContainer').html(d);
            });

But it’s retuning only the basic html structure, not the dynamic html which in SPA is generated by AJAX (I’m wondering if this is why SPA are not good for SEO).

I believe might exist some technique/trick to solve this problem. Chrome for example when you inspect elements it’s able to render all html from AJAX.

Maybe I’m not using the right keywords on google. What people has been doing to workaround this problem?

UPDATE:

Just to be clear about my case. I’m trying to get the full html from this SPA to display to the user a template preview.

I have many different SPA with different templates. I want to display these live templates by AJAX instead IFRAME. With IFRAME works but isn’t great.

2

Answers


  1. You can generate a full page in a SPA, but that’s not the goal you should not use a SPA in that case.

    Because the goal of a SPA is to get only some pieces of the page and load them when necessary you should try a middleware if you care about SEO crawlers like prerender.io you can create you own server with it or use their services its open source.

    but generating a full page in SPA is killing all the reasons why you should use a SPA. Best Regards 🙂

    Login or Signup to reply.
  2. You’ll get the raw html because the server doesn’t render your app and this is the expected behaviour, there is no bug.

    S.P.A are usually ClientSide applications, it means that the browser have to render at rountime the AngularApp!

    Of course the browser no renders anything because your code is async-injected into the dom, so, you need to program the AngularJS bootstrapping manually not through the ng-app directive.

    by the way, there are many ways to have a server-side rendering of your app, have a look on https://prerender.io/

    If your goal is have a good indexing… loading the app via jQuery is a bad solution because search-engine-crawlers aren’t able to process javascript, this is not a angular specific issue, each app built in javascript has this problem.

    The best solution should be have a full angular-app and, only for crawlers, implement a server-side prerendering (using prerender.io).

    Hope helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search