Generate static versions of AngularJS pages?

931 views
Skip to first unread message

Alec Taylor

unread,
Dec 29, 2012, 2:21:30 AM12/29/12
to ang...@googlegroups.com
I want to generate static versions of AngularJS pages for use by web-scrapers and people without JavaScript enabled.

The line I'm currently following is to render the page in Python using some proper render—like Gecko or WebKit—then store the HTML it generates.

But maybe I can do it from the other end; i.e.: generate the static HTML using AngularJS?

(or maybe Node.js)

Thanks for all suggestions,

Alec Taylor

PS: For my progress on the render-from-Python method, see: http://stackoverflow.com/questions/14079416/render-javascript-to-html-in-python

Witold Szczerba

unread,
Dec 30, 2012, 9:28:03 AM12/30/12
to ang...@googlegroups.com
Hi,
you can have hard time working on generating HTML only snapshots of
AngularJS applications, as this is an application environment, not a
static page generator. Of course you can try and it might partially
work, but you must think of it as you were doing screenshots of
desktop/console applications, because most of the things won't work
like buttons for example... all directives will be gone, all
controllers, services will be gone.
Another question is how to get the HTML snapshot from... Have you
tried headless browsers like PhantomJS?

Regards,
Witold Szczerba
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
>
>

Alec Taylor

unread,
Dec 30, 2012, 9:34:18 AM12/30/12
to ang...@googlegroups.com
I have looked at PhantomJS; but found its documentation to be lacking.
If you can help me rig up an example with it that'd be appreciated.

And yes, I know the static versions will be missing most of the things
which we use AngularJS for; but at the same time I think they benefits
of graceful degradation speak for themselves.

I have built in a little solution using Python:
http://stackoverflow.com/a/14088609/587021

However it's by no means perfect; the biggest limiting factor is that
I can't run it on Public PaaS's like Heroku and Red Hat's: OpenShift.

PhantomJS—being a C++ project—would be even more unlikely to be
runnable on a PaaS.

The best and most efficient—once implemented—solution would be to
generate the static files using the AngularJS framework itself.

Any help on that front or on any other PaaS-runnable solution would be
greatly appreciated.

Thanks

On Mon, Dec 31, 2012 at 1:28 AM, Witold Szczerba <pljos...@gmail.com> wrote:
> PhantomJS
Reply all
Reply to author
Forward
0 new messages