DEV Community


Server Optimization

dhiranegi profile image DhiraNegi ・2 min read

For better performance of the webservers, server optimization is done.
Checkout the previous post for adding web contents to arduino sketch for a webserver running in esp8266.

Simple minification techniques can be used for removal of tabs and whitespaces. Many online tools are available for that. I use
Compress your html and custom js and css file.(graphics and text files can't be compressed using this)

Using GZIP compression Techinque

Download 7-zip .

It's good to make a GZIP folder to keep all your zipped versions of files. To minified versions of files, apply gzip compression.
(7-Zip>add to archive).

For adding GZIPPED files to arduino sketch, replaces C String with HEX values(convert the files to HEX values with any online tool like

Server has to inform clients that the data being sent is in GZIP format, that is done with content-encoding header by using server.sendHeader() function. Sending "content-encoding" "gzip" header for all server files. Here is one handler function and should be done for all the handler function in the code.

Alt Text

You can verify Content compression and server response time reduction with wireshark.
It is possible to further speed up server response time and reduce bandwidth usage by using cache control or expires header.

ESP Arduino core has some flash memory reserved for file system
called SPI Flash file system. You can choose from Tools>Flash Size

Flash Layout:
Alt Text

Follow the installation process from

Make a folder "data" inside arduino sketch folder and place all GZIPPED files inside that. Do Sketch Data Upload.
You can remove arrays and handler functions from arduino sketch.

Reading files with file system library

You can find an examples here :
File>Examples>ESP8266WebServer>FSBrowser and study it.

Include FS.h library in your arduino code and initialize it by calling begin function in setup(SPIFFS.begin();)
Call handleFileRead() inside server onNotFound(). You can also send expires header before stream file function is called.

Get the code

The method is same for mikroC TCP/IP libaray. Add HTTP header in simple uncompressed form on Start of Gzipped array, then use


for sending only single array that contains both HTTP header and Gzipped data.
Use exactly same technique for STM32 or any other ARM chip with Lwip TCP/IP stack.


Discussion (0)

Editor guide