Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:13:12+00:00 2026-05-31T20:13:12+00:00

Assuming a JavaScript-based single-page application is returned by the server on the initial request.

  • 0

Assuming a JavaScript-based single-page application is returned by the server on the initial request. Besides some initialization code, which is common for every application, just the portion of the application needed to show the requested page (e.g. index page) is returned by the server on the initial request (then cached and rendered).

As the user clicks through the application, other portions of the application should be asynchronously loaded (‘fetched’, ‘requested’ or however you wanna call it) from the server. By “portions” a mean javascript code, images, css, etc. required to render the page. Let’s focus on the javascript code part in this discussion.

It’s important to notice that the javascript code to be returned to the browser is not contained in separate (static) files (which would be easy then and might be the case in the future due to e.g. performance reasons), but rather in one file, so it’s not a 1:1 assiociation (request : file).

E.g. we could have a single app defined like this:

var LayoutPresenter = App.Presenter.extend('LayoutPresenter', {
  __view: '<div>{{link "Author" "/author"}} - {{link "Book" "/book"}}</div>'
});

var AuthorPresenter = App.Presenter.extend('AuthorPresenter', {
  __view: '<div><h1>{{name}}</h1></div>',
  __parent: LayoutPresenter,
  __context: { name: "Steve" }
});

var BookPresenter = App.Presenter.extend('BookPresenter', {
  __view: '<div><h1>{{title}}</h1></div>',
  __parent: LayoutPresenter,
  __context: { title: "Advanced JavaScript" }
});

App.Presenter is part of the library I am writing and is available in the browser (or on any other client).

So assuming the user is browsing to the Book page which hasn’t be loaded before (neither initially nor cached in the browser), the BookPresenter code, which is a function, should be returned by the server (assuming the LayoutPresenter code is already available in the browser and App.Presenter is available anyway because it’s part of the library). I am running node.js on the server side.

How would you recommend to address this problem?

There is the eval function, so one could send javascript as a string and bring it back to live using eval(), but such an approach seems to be bad practice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:13:13+00:00Added an answer on May 31, 2026 at 8:13 pm

    Never use eval – it’s evil. The better option would be use jQuery ajax and set the dataType as script. This will evaluate your js, and also provide you with a call back once the script is loaded.

    Refer to Ajax dataTypes and jQuery getScript shorthand. This is of course assuming that you can separate your code into logical modules

    You might also consider it worth your time to check this question (How can I share code between Node.js and the browser?)

    dNode is an option that is described in the question above and it looks quite exciting in terms of possibilities. You could create a list of function required for the Book page, then call them right off the server itself. That would eliminate the need to maintain separate js modules for each section of your page. Kudos to @Caolan for suggesting it.

    As interesting as it is, take care to properly scope your functions; you don’t want random users playing around on your server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to code a secure and lightweight white-list based HTML purifier which will
Assuming points are represented using JavaScript Array as [x,y] , how could I define
Assuming I have a JavaScript function like this... function Object1() { this.var1; this.var2; this.var3;
Assuming network access is sporadic with no central server, what would be the best
Assuming I have an open source web server or proxy I can enhance, let's
Javascript noob here (I'm assuming I will need Javascript to solve this). I need
Assuming I have a valid session and an authenticated user, what are some ways
Goal: To develop a web based NMS interface which displays a network topology (e.g.,
I just coded a function using the Javascript for...of loop , assuming it had
Being quite new at JavaScript, I'm assuming the answer to my question is extremely

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.