When a visitor accesses your website, their browser requests multiple files like images, stylesheets, and scripts from your server. Without Keep-Alive enabled, the browser has to open a brand new connection for every single file it needs to download. This constant opening and closing of connections causes significant network latency and slows down your page rendering.
Enabling Keep-Alive tells your server to leave the network connection open, allowing the visitor's browser to download all necessary files through a single, continuous pipeline. This simple tweak drastically reduces the time it takes to deliver your website's assets, instantly improving your scores on speed testing tools.
Step 1: Accessing Your .htaccess File
You can enable this feature by adding a brief snippet of code to your website's hidden configuration file directly from your hosting dashboard.
-
Log in to your Sternhost cPanel account.
-
Navigate to the Files section and click on File Manager.
-
Click on Settings in the top right corner and check the box for 'Show Hidden Files (dotfiles)'.
-
Open your website's main directory, which is usually named public_html.
-
Right-click on the .htaccess file and select Edit.
Step 2: Adding the Keep-Alive Rules
Once the text editor is open, you will add the specific header instructions that force the server to maintain open connections.
-
Scroll to the very bottom of the document to ensure you do not interfere with any existing WordPress rules.
-
Copy and paste the following snippet directly into the editor:
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
-
Click the Save Changes button in the top right corner of the screen to apply the configuration.
Why Keep-Alive is Essential for Performance
-
Eliminates Connection Latency: Browsers no longer waste precious milliseconds constantly asking the server for permission to download the next individual file.
-
Reduces Server CPU Load: Opening and closing hundreds of individual connections requires server processing power, whereas leaving one connection open is much more resource-efficient.
-
Boosts Simultaneous Downloads: It allows modern web browsers to pull multiple graphical and structural assets at the exact same time, rendering your website instantly.
