What is the best way to do multi-page application in angularjs

7,232 views
Skip to first unread message

Samantha Atkins

unread,
Jun 27, 2013, 3:40:03 PM6/27/13
to ang...@googlegroups.com
I have a two page application running fine except I have an ugly hack in that both pages have the same boilerplate (mostly) and both have an ng-app=my_app in them.  Which means that both in fact bootstrap the application.  I want to avoid that.  Is there a good way to make this happen?  Please refrain for now from telling me I should give up and make it a single page application.  

A related question, does multi-page app generally need to load the javascript it uses?  In other words, when is the javascript loaded by one page unloaded?

Thanks!

Grant Rettke

unread,
Jun 27, 2013, 3:46:06 PM6/27/13
to ang...@googlegroups.com
On Thu, Jun 27, 2013 at 2:40 PM, Samantha Atkins <sjat...@gmail.com> wrote:
> I have a two page application running fine except I have an ugly hack in
> that both pages have the same boilerplate (mostly) and both have an
> ng-app=my_app in them. Which means that both in fact bootstrap the
> application. I want to avoid that. Is there a good way to make this
> happen? Please refrain for now from telling me I should give up and make it
> a single page application.

Good question. 'angular' is exposed at the top-level, so, could that
be an issue?

I'm pretty curious to hear the NG/JS masters reply; and have seen
other posts on the topic before.

mark prades

unread,
Jun 27, 2013, 4:59:19 PM6/27/13
to ang...@googlegroups.com
when is the javascript loaded by one page unloaded?

The javascript is unloaded when the browser request a new html page on the server.

does multi-page app generally need to load the javascript it uses? 

you can cache the js files with http headers, and yes of course the javascript need to be loaded , parsed and executed

I want to avoid that.

You wont ,since you have 2 different html pages request by the browser. 

Please refrain for now from telling me I should give up and make it a single page application.  

You have a "problem" (which is not since it is how the web works) , there is a solution , but you basically dont want to consider that solution for unknown reasons. This is not how you should think as a developer. You should dismiss a solution only if it doesnt meet the requirements of the product you are building. 

Good luck.

Grant Rettke

unread,
Jun 27, 2013, 5:01:00 PM6/27/13
to ang...@googlegroups.com
On Thu, Jun 27, 2013 at 3:59 PM, mark prades <parais...@gmail.com> wrote:
>> when is the javascript loaded by one page unloaded?
>> Please refrain for now from telling me I should give up and make it a
>> single page application.
>
> You have a "problem" (which is not since it is how the web works) , there is
> a solution , but you basically dont want to consider that solution for
> unknown reasons. This is not how you should think as a developer. You should
> dismiss a solution only if it doesnt meet the requirements of the product
> you are building.

Technically you didn't say not but you came impressively close lol.

Michael Bielski

unread,
Jun 27, 2013, 5:07:50 PM6/27/13
to ang...@googlegroups.com
I faced a similar issue some months ago. In the end, the solution I took was to bite the bullet and go with the SPA because that is the only way to avoid what you are experiencing. The end result is that my SPA is faster and more responsive than my 4 pages ever were. When you consider the mobile platforms this becomes even more important.

Of course, it is your project to do with as you wish. Best of luck to you.

Larry Clapp

unread,
Jun 27, 2013, 5:16:59 PM6/27/13
to ang...@googlegroups.com
> Is there a good way to make this happen?

The only way I know is that you should "give up and make it a single page application."  :)

If you can't do that, then yeah, you have to bootstrap Angular per page.

While this is slower than doing a single page app, I wouldn't think horribly so.  After the first page the browser caches the js, so it's just a matter of loading the new page; the js is already there.

You might get some better or more helpful or at least more understanding answers if you said why you can't make a single page app.

-- Larry

Dan Kang

unread,
Jun 27, 2013, 6:30:49 PM6/27/13
to ang...@googlegroups.com
There's no good way to do this, but if you really have to do this to collect on bets or something, you can load the scripts and do boilerplate in an outer frame (and nothing else) and have a multi-page server-side navigation app inside an iframe and have the iframe get necessary resources from the outer frame and run two applications in parallel.

This is not a serious recommendation, of course.

On Thursday, June 27, 2013 3:40:03 PM UTC-4, Samantha Atkins wrote:
Reply all
Reply to author
Forward
0 new messages