angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

[feature request] Server-side rendering

Open artem-popov opened this issue 12 years ago • 12 comments

Will be great for fast page load and SEO

artem-popov avatar Jan 10 '14 08:01 artem-popov

+1

anvarKhakimov avatar Jan 10 '14 08:01 anvarKhakimov

+1

Kadae avatar Jan 10 '14 08:01 Kadae

+1

gsklee avatar Jan 10 '14 08:01 gsklee

+1

isRuslan avatar Jan 10 '14 08:01 isRuslan

there is a whole bunch of services out there that can take care of SEO problem with very little hassle. Quick google search reveals a bunch of them. I'm not familiar with any of them so I'm not going to share any names in order not to make an impression of an endorsement.

if you want to run your own setup (which sounds like you are since you want server-side prerendering) then check out this yearofmoo article http://www.yearofmoo.com/2012/11/angularjs-and-seo.html

IgorMinar avatar Jan 10 '14 08:01 IgorMinar

dupe of #2104

IgorMinar avatar Jan 10 '14 08:01 IgorMinar

Thank you! Although I use one of such solutions (custom with zombiejs) I can't call it good solution.. It has many disabilities and all of them are summarized in fact that we need pay time for supporting this render separatelly. And with real render this can be achieved automatically.

some of disabilities:

  • each rendered page individually should declare the time when it's finished rendering
  • rendered page is not exactly the same as browser version. (even phantomjs, which doesn't support es5)
  • it is very slow
  • it is only for SEO

artem-popov avatar Jan 10 '14 08:01 artem-popov

Maybe instead of server-side rendering, we could specify default content in Angular somehow? Perhaps if JS is disabled, or the page is slow (and assuming you aren't using ng-cloak to hide the raw templates), default content could be shown. ¯\_(ツ)_/¯ 

kevinSuttle avatar Apr 10 '14 19:04 kevinSuttle

I think the browser already lets you add content for when JS is disabled, using the <noscript> tag.

caitp avatar Apr 10 '14 19:04 caitp

Actually, there is a better way. If you use a directive, it will only work if JS is enabled. So, if you wrap the noscript content in a directive, it will appear if JS is disabled.

Example: This is the both pre-rendered markup, and markup that appears if JS is turned off. The browser will just ignore the attribute, and render the div normally.

<div data-context-selector>
    <select>
         <option value="Any app">Any app</option>
         <option value="Blog Engine">Blog Engine</option>
         <option value="Ruby Gem Search">Ruby Gem Search</option>
         <option value="Project Manager">Project Manager</option>
    </select>
</div>
appDirectives.directive("contextSelector", function() {
    return {
        templateUrl: '/views/components/context-selector.html',
        replace: true
    }
});

If JS is enabled, the noscript content is replaced with your directive.

<div class="context-selector">
    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
        {{getAppName(selectedApp)}} <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" role="menu" ng-model="app">
        <li ng-repeat="app in catalog.apps" ng-click="selectApp(app)">{{getAppName(app)}} - {{getAppRuntime(app)}}</li>
    </ul>
</div>

kevinSuttle avatar May 22 '14 15:05 kevinSuttle

@kevinSuttle & @IgorMinar - Is the discussion for server side rendering going to continue on #2104 or this thread? It would be nice to have a centralized forum for discussion as this is an issue thats not only pertinent to SEO but also is useful for heavily-trafficked sites.

hiravgandhi avatar May 28 '14 17:05 hiravgandhi

@hiravgandhi We can continue wherever makes the most sense.

kevinSuttle avatar May 28 '14 18:05 kevinSuttle