Jump to content

JavaScript & CSS Source file loading efficiency


barneyf

Recommended Posts

I am building an application where PHP will refresh the web page on user command.  I have references to a CSS and JavaScript file in the head section of the document:

 

<head>
<script type="text/javascript" src="myscript.js"></script>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>

 

Does the browser (FireFox or IE) re-load the CSS & JavaScript source files every time the page is re-sent?  Or is it smart enough to know it already has it loaded?

 

I am using CSS frames, not HTML frames and I am not ready to go to Web 2.0 with Ajax & etc just yet.  So if the browser blindly loads the files each time, is there a simple workaround?

 

Thanks

Link to comment
Share on other sites

I hate the phrase Web 2.0.

 

 

 

And yes, browsers are smart enough to cache things, assuming the server is intelligent enough to know it's cached.  (Even IE does somethings right.  Weird, eh?)

 

 

The way it basically works is this (there are other factors, such as whether the server tells the client to cache the content or not):

 

*Client connects to server*

*Client sends request to server for something, but also says if it has a cached copy, and if so, when the cached copy was cached.*

*If the cached copy on the client side is the newest version, the server just tells the client that and nothing is transfered.*

 

 

So yes, there is a little bandwidth used because of the HTTP headers, but the entire file is not transfered.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.