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 8471091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:42:05+00:00 2026-06-10T16:42:05+00:00

What is currently the best practice for loading models (and goes for all required

  • 0

What is currently the best practice for loading models (and goes for all required files I guess)?

I’m thinking these two ways to achieve the solution (nonsense code to illustrate follows):

var Post = require('../models/post');

function findById(id) {
    return new Post(id);
}

function party() {
    return Post.getParty();
}

vs

function findById(id) {
    return new require('../models/post')(id);
}

function party() {
    return require('../models/post').getParty();
}

Is one of these snippets preferred? Are there considerable memory and time tradeoffs? Or is it just a premature optimization?

  • 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-06-10T16:42:07+00:00Added an answer on June 10, 2026 at 4:42 pm

    It’s a premature optimization (calls to require() are cached and idempotent), but I’d personally call your first style better (loading dependencies during initialization rather than subsequent processing) since it’s easier to get your head around what you’re doing. Loading everything at the start will slightly slow down your startup (which is hardly ever an issue) in return for making most requests run slightly faster (which you shouldn’t worry about unless you’ve identified a bottleneck and done some hardcore profiling).

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

Sidebar

Related Questions

What is the best practice to use these two methods for memory management? My
I'm pretty new to the Symfony Framework and currently searching for the Best-Practice way
I'm unsure on the best stack to build a chat application. Currently I'm thinking
I am currently looking for an intelligent best practice solution for the following problem.
I'm currently rebuilding an admin application and looking for your recommendations for best-practice! Excuse
Currently trying to come up with a best practice for a ZF site that
What is best practice, what delivers the best performance? I currently have a query
I'm looking for a best practice on shutting down an OSGi container. Currently we
Is there a REST best practice for GETting resources in different languages. Currently, we
I'm trying to establish a best practice for Virtual Machines for developers. Currently we

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.