# Optimising web requests

> Speed up your website by reducing and optimising the web requests each page makes, from DNS lookups to caching.

Source: https://helpcenter.ruachost.com/apps/guides/optimizing-web-requests/

Every time a visitor loads your website, their browser sends a **web request** to your server. Optimizing these requests ensures faster page loads, reduced latency, and better overall performance. On **ruachost.com**, you can improve performance by fine‑tuning each stage of the request lifecycle.

## Why Optimize Web Requests?

- Faster website response times.
- Reduced server load and bandwidth usage.
- Improved SEO rankings (Google favors faster sites).
- Better user experience, especially for global audiences.

## Stages of a Web Request & Optimization Tips

### 1. **DNS Lookup**

- Converts domain names (e.g., `example.com`) into IP addresses.
- ### Optimization

  - Use reliable DNS servers (e.g., ruachost.com  name servers).
  - Set appropriate **TTL (Time to Live)** values (between 4–6 hours).
  - Lower TTL before planned IP changes for faster propagation.

### 2. **Establishing a Connection (TCP Handshake)**

- Browser and server exchange SYN, SYN‑ACK, and ACK packets.
- ### Optimization

  - Host servers close to your customer base to reduce latency.
  - Use CDNs (Content Delivery Networks) for global reach.

### 3. **Negotiating SSL Handshake**

- Browser and server establish encrypted communication.
- ### Optimization

  - Position servers strategically near users.
  - Use modern SSL/TLS protocols for faster negotiation.

### 4. **Sending a Request**

- Browser sends URL, cookies, sessions, headers, and form data.
- ### Optimization

  - Limit cookie size and unnecessary hidden fields.
  - Use session cookies instead of passing variables in forms.
  - Only send essential data.

### 5. **Wait Time (Server Processing)**

- Time between server acknowledgment and first byte of response.
- ### Optimization

  - Optimize application code and database queries.
  - Disable unnecessary plugins/extensions in CMS platforms.
  - Use caching engines (e.g., W3 Total Cache for WordPress, Boost for Drupal, Magento Cache).
  - Tools like **New Relic** can identify slow functions.

### 6. **Receiving a Response**

- Browser downloads content generated by the server.
- ### Optimization

  - Enable **minification** of HTML, CSS, and JS.
  - Use **Gzip compression** (`mod_deflate` in Apache).
  - Combine CSS/JS files to reduce requests.
  - Optimize images before upload.

> **Note:**
- The biggest performance gains often come from **caching engines**.
- Always test changes with tools like **Pingdom**, **GTmetrix**, or **Chrome DevTools**.
- Consider enabling **Redis or Memcached** for advanced caching.
