Page 1 of 1

Load Time: PHP vs. External JavaScript File

Posted: Thu Apr 03, 2008 11:47 am
by chitownclone
I manage a number of web site and am attempting to centeralize some of common by frequently updated content and images. Because this content needs to be somewhat personalized for user groups, I am envisioning a Google Adsense like application (however no where near as complex).

I have two options:
One is to use an external javascript file sitting on a centeralized server. This external javascript file would pull in additional configuration files, also sitting on the server, that are related to the page URL (and additional personalization parameters) requesting the javascript file.

Code: Select all

<script type="text/javascript" src="http://central_server.com/external_file.js"></script>
Second, and preferred, method would be to use a php script to use parameter passed in the URL string to dynamically generate configured javascript which would be returned to the browser just as the external_file.js would.

Code: Select all

<script type="text/javascript" src="http://central_server.com/external_script.php?site_id=3"></script>
My Question
How much additional load time (insignificant, moderate, signifiant) will the php option require?
- If it uses xml files (on the php server) for configuration data
- If it uses MySQL database for configuration data

Obviously using the PHP enable some of my content serving logic to be cloaked compared to javascript. Plus changes and updates would be much easier to manage compared to constantly generating and regenerating the javascript files...but is it worth it.

Thanks

Re: Load Time: PHP vs. External JavaScript File

Posted: Thu Apr 03, 2008 1:46 pm
by Christopher
Sounds like it is worth it. I would implement it right and then deal with performance as needed. You could easily add a simple cache functionality into the script to reduce database or XML processing if needed.

Re: Load Time: PHP vs. External JavaScript File

Posted: Fri Apr 04, 2008 2:36 am
by Rovas
Using xml files is much faster than using queries to the MySql server and the second method is better because GET method is cached by the server so you have only to implement some rules on dealing with them in the server\ browser cache.