Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this an optimization?

Does going from

<script type="text/javascript" src="jquery.js"></script>

to

<script type="text/javascript">
  <?php echo file_get_contents('jquery.js'); ?>
</script>

really speed things up?

I am thinking it does because php can fetch and embed a file's contents faster than the client's browser can make a full request for the file, because php isn't going over the network.

Is the main difference that the traditional method can be cached?

like image 516
Devin Rhode Avatar asked Aug 14 '11 15:08

Devin Rhode


People also ask

What do you mean optimization?

Definition of optimization : an act, process, or methodology of making something (such as a design, system, or decision) as fully perfect, functional, or effective as possible specifically : the mathematical procedures (such as finding the maximum of a function) involved in this.

What is an example of optimize?

To optimize is to make something the best it can be. When you tweak a report that you are writing to improve the content and format, this is an example of when you optimize the report. (originally intransitive) To act optimistically or as an optimist.

What is optimization used for?

Optimization methods are used in many areas of study to find solutions that maximize or minimize some study parameters, such as minimize costs in the production of a good or service, maximize profits, minimize raw material in the development of a good, or maximize production.


2 Answers

It may be faster on the first page load, but on every subsequent load it will be much slower. In the first example, the client browser would cache the result. In the second, it can not.

like image 176
nickf Avatar answered Oct 05 '22 23:10

nickf


If you only ever serve one single website in your client's life, then yes, because you only have one HTTP request instead of two.

If you are going to serve multiple sites which all link to the same javascript source file, then you're duplicating all this redundant data and not giving the client a chance to cache the file.

like image 31
Kerrek SB Avatar answered Oct 05 '22 23:10

Kerrek SB