Caching large JS file in a web server

Hey all,
I am using a Arduino Mega with an Ethernet shield and SD to host a couple of web pages. Ultimately the Mega is controlling a power supply and the pages provides the GUI.

Everything is running fine so far, but I am trying to implement a real time V/I chart using the CanvasJS Charts library which is about 275KB.

I have put the chart library file on the SD card and have added the script reference to the HTML. When the client requests the library file, code in the Arduino reads the file from the SD and sends it to the client. My problem is that it takes nearly 60 seconds for the file to load in the browser. What I want to do is cache the library on the client side. I’m not sure how to do this.

On the client side, I am including the script with this code…

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

which triggers a “GET /canvas.js HTTP/1.1” request sent to the Arduino when the client connects to the Arduino.

When the Arduino receives the GET I am running the following code…

void sendWebFile(char *fName, char *mimeType, unsigned int cacheSeconds,  EthernetClient cl)
{

  webFile = SD.open(fName);        // open web page file
  if (webFile)
  {
    if (cacheSeconds != 0)
    {
      cl.print("Cache-Control: max-age=");
      cl.println(cacheSeconds);
    }

    cl.println(mimeType);
    cl.println("Connection: keep-alive");
    cl.println();

    while (webFile.available()) {

      cl.write(webFile.read()); // send web page to client
    }
    webFile.close();
  }
  else
  {
    Serial.println("file not foud!");
  }
}

where the argument passed to the method are
fName =“canvas.js”
mimeType = "“Content-Type: text/javascript”
cacheSeconds = 31536000

For this file the response includes a Cache-Control: max-age value in a attempt to tell the client to cache to file and use it. It’s obviously not working.

I realize this is probably not an Arduino question, but someone has got to have done this before.

What I need to know is how to tell the browser that if there is a cached copy use it, but if not I need to send it from the Arduino.
Anyone know how to do this???