# Inline Style Aggregation Drupal Module

## Overview

**Inline Style Aggregation** is a Drupal module that optimizes the delivery of inline CSS styles in HTML responses. By aggregating inline `<style>` tags, it helps reduce page size, improve frontend performance, and streamline the rendering of styles for site visitors.

---

## Features

- **Inline CSS Aggregation:** Automatically collects and aggregates all inline `<style>` tags from HTML responses.
- **Performance Optimization:** Reduces the number of style blocks and overall HTML size, improving page load times.
- **Event Subscriber Architecture:** Uses a Symfony event subscriber to process HTML responses before they are sent to the browser.
- **Seamless Integration:** Works transparently with Drupal’s rendering pipeline; no configuration required for basic usage.

---

## Folder Structure

```
inline_style_aggregation/
├── composer.json
├── inline_style_aggregation.info.yml
├── inline_style_aggregation.module
├── inline_style_aggregation.services.yml
├── LICENSE.txt
├── README.txt
└── src/
    └── EventSubscriber/
        └── InlineStyleAggregationHtmlResponseSubscriber.php
```

---

## Main Functionalities

### 1. Inline CSS Aggregation

- **InlineStyleAggregationHtmlResponseSubscriber.php:**  
  - Listens to HTML responses using Drupal’s event system.
  - Parses the HTML output and finds all `<style>` tags.
  - Aggregates the contents of these tags into a single `<style>` block.
  - Replaces the original multiple `<style>` tags with the aggregated block, reducing redundancy and improving efficiency.

### 2. Performance Optimization

- By minimizing the number of inline style blocks, the module helps browsers process styles faster and reduces the overall size of the HTML response.

### 3. Transparent Operation

- The module works automatically when enabled. No configuration is needed for basic aggregation.
- Designed to be compatible with most Drupal themes and modules.

---

## Usage

### Installation

1. Place the module in your Drupal installation’s `modules/custom` directory.
2. Enable the module via the Drupal admin interface or with Drush:
   ```bash
   drush en inline_style_aggregation
   ```

### How It Works

- After enabling, every HTML response generated by Drupal will be processed by the event subscriber.
- All inline `<style>` tags are aggregated into a single block before the response is sent to the browser.

### Configuration

- No configuration is required for basic usage.
- Advanced users can extend or modify the event subscriber for custom aggregation logic.

---

## Key Classes & Files

- **src/EventSubscriber/InlineStyleAggregationHtmlResponseSubscriber.php:**  
  The core event subscriber that performs the aggregation of inline styles.

- **inline_style_aggregation.module:**  
  Module file for hook implementations (if needed).

- **inline_style_aggregation.services.yml:**  
  Registers the event subscriber service.

---

## Requirements

- Drupal 10

---

## Extending

- Developers can extend the event subscriber to add custom logic for style aggregation, filtering, or optimization.
- The module can be integrated with other frontend optimization tools for enhanced performance.

---

## License

See `LICENSE.txt`.

---

## Support

For issues or feature requests, open an issue in your repository or contact the maintainer.
