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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:59:02+00:00 2026-06-10T23:59:02+00:00

I am new to Javascript and development in general and have an absolute beginner’s

  • 0

I am new to Javascript and development in general and have an absolute beginner’s question: I would like to know more about the advantages and disadvantages of the following two constellations, especially regarding execution speed and server load/requests.

  1. Put all custom JS code inside PHP code and call it from there

  2. Put all custom JS code inside a custom.js and just call the JS functions in PHP

On the one hand I prefer to keep all my JS code separated to have things tidy and clean but on the other hand I imagine that it takes longer to load the page due to an additional server request. Will there be a noticeable speed difference when I put all code in a custom JS file? Are there any specific scenarios where it’s recommend to put the JS inside the PHP or keep it separated?

Thanks

  • 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-10T23:59:03+00:00Added an answer on June 10, 2026 at 11:59 pm

    JS in separate file – additional request. But I would not say that is a problem because it will be cached by browser. If you have a lot of js files – collect them into a single file to avoid multiple requests (there are special tools to compile separate JS files into one file and minimize its size).

    Placing it into PHP code is just terrible. It should be in separate file.

    On the one hand I prefer to keep all my JS code separated to have things tidy and clean but on the other hand I imagine that it takes longer to parse the whole code.

    Why? JS is executed on client side. Not on server side. PHP will not parse JS files. At the same time – if you will put a JS code in PHP file – PHP will need to echo it to browser and that is additional work for PHP engine. Plus, in PHP code it will be sent to browser any time when PHP is executed.

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

Sidebar

Related Questions

I'm new to PHP (and web development in general) and have come across something
I am very new to web development and Javascript in general and I hae
I'm fairly new to facebook development, but have experience with PHP and JavaScript. I've
I'm new here (and to web development in general), and I have been trying
I'm a bit new to web development so forgive the slightly beginner question. Can
I'm fairly new to Javascript development so this might be a real newbie question.
I am quite new to JavaScript and just started some more serious development in
I am trying to do some javascript test driven development, and would like to
I am new into Facebook application development and also newbie about JavaScript and PHP
I'm an actionscript developer getting into jquery/javascript development. I have a question regarding event

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.