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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:22:05+00:00 2026-05-23T00:22:05+00:00

From a tutorial I read on Sitepoint, I learned that I could load JS

  • 0

From a tutorial I read on Sitepoint, I learned that I could load JS files through PHP (it was a comment, anyway). The code for this was in this form:

<script src="js.php?script1=jquery.js&scipt2=main.js" />

The purpose of using PHP was to reduce the number of HTTP requests for JS files. But from the markup above, it seems to me that there are still going to be the same number of requests as if I had written two tags for the JS files (I could be wrong, that’s why I’m asking).

The question is how is the PHP code supposed to be written and what is/are the advantage(s) of this approach over the ‘normal’ method?

  • 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-23T00:22:05+00:00Added an answer on May 23, 2026 at 12:22 am

    The original poster was presumably meaning that

    <script src="js.php?script1=jquery.js&scipt2=main.js" />
    

    Will cause less http requests than

    <script src="jquery.js" />
    <script src="main.js" />
    

    That is because js.php will read all script names from GET parameters and then print it out to a single file. This means that there’s only one roundtrip to the server to get all scripts.

    js.php would probably be implemented like this:

    <?php
    $script1 = $_GET['script1'];
    $script2 = $_GET['script2'];
    
    echo file_get_contents($script1); // Load the content of jquery.js and print it to browser
    echo file_get_contents($script2); // Load the content of main.js and print it to browser
    

    Note that this may not be an optimal solution if there is a low number of scripts that is required. The main issue is that web browser does not load an infinitely number of scripts in parallel from the same domain.

    You will need to implement caching to avoid loading and concatenating all your scripts on every request. Loading and combining all scripts on every request will eat very much CPU.

    IMO, the best way to do this is to combine and minify all script files into a big one before deploying your website, and then reference that file. This way, the client just makes one roundtrip to the server, and the server does not have any extra load upon each request.

    Please note that the PHP solution provided is by no means a good approach, it’s just a simple demonstration of the procedure.

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

Sidebar

Related Questions

I am trying to read some Java code from a tutorial, I don't understand
This code is from Prototype.js . I've looked at probably 20 different tutorials, and
I read the tutorial from IBM development website. http://www.ibm.com/developerworks/xml/library/x-googleclndr/#resources I tested successfully. Now I
I am using following a tutorial from here: http://www.shopdev.co.uk/blog/cookies-with-jquery-designing-collapsible-layouts/ This is the script I
I am having a couple problems with the code from the tutorial: ListView Tutorial
I've read the tutorial at, and I generally get how that works: http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#simple I
Does anyone know of a tutorial on how to read data from a server
Thanks to this excellent tutorial , I know how to read a string (in
Hi I'm trying to read all files from a given server. What I want
I'm using a chart taken from here http://writerbay.wordpress.com/2011/03/12/android-tutorial-displaying-chart-on-android/#comment-54 to draw a graph in android.

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.