I am working with an official Arduino Mega. I have mounted an officiel Ethernet Shield rev 2.

Everything works great, i have wrote a very basic webserver.

I wanted to host a bootstrap css file on my webserver. This file has a size of about 150 kilo-bytes. So i have inserted an SD card on the Ehternet Shield. I have put my css file on this SD card.

I am writing the content of my css file with this code:

File myFile = SD.open("bootstrap.min.css");
if (myFile) 
    byte clientBuf[2048];
    int clientCount = 0;              
    while (myFile.available()) 
        clientBuf[clientCount] = myFile.read();

        if(clientCount > 2048-1)
            clientCount = 0;
     if(clientCount > 0) client.write(clientBuf,clientCount);            

It works, but it is very slow. It takes about 30-40 seconds to load file into my browser. I have tried to change clientBuf size but this is the optimal value i've set.

Any idea ?


  • you should set Expires: header to let the browser cache the file. and set the content-length header to let the browser know how many bytes to expect. github.com/jandrassy/Regulator/blob/…
    – Juraj
    Mar 20 '19 at 13:06
  • I agree but it will be slow for first load...
    – Bob5421
    Mar 20 '19 at 13:12
  • sorry, my largest file is only 10 kB. can you load framework files from Internet?
    – Juraj
    Mar 20 '19 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.