An open API service indexing awesome lists of open source software.

https://github.com/redrootdev/goprerender

GoPrerender - A high-performance Go-based prerendering service that renders JavaScript-heavy web pages using Headless Chrome and serves them as static HTML with caching support. 🚀
https://github.com/redrootdev/goprerender

chromedp golang javascript prerender prerendering prerenderio react

Last synced: 3 months ago
JSON representation

GoPrerender - A high-performance Go-based prerendering service that renders JavaScript-heavy web pages using Headless Chrome and serves them as static HTML with caching support. 🚀

Awesome Lists containing this project

README

        

# GoPrerender

GoPrerender is a high-performance prerendering service built in Go that renders JavaScript-heavy web pages and serves them as static HTML. It utilizes Headless Chrome (via `chromedp`) and an in-memory cache (`ristretto`) to optimize responses.
Originally designed to Prerender my website https://mrivals.gg as I was unhappy with the performance of Prerender (NPM) but I have decided to make it public.

## Features
- **Fast and lightweight** prerendering for JavaScript-heavy websites
- **Caching** with customizable TTL to improve performance
- **Configurable** timeout and stability checks for HTML rendering
- **Domain whitelisting** for controlled access
- **Uses Headless Chrome** for accurate rendering

## Prerequisites
Ensure you have the following installed:
- **Docker**
- **Docker Compose**

## Installation & Setup

### Using Docker Compose
To run the application using Docker Compose:

```sh
docker-compose up -d
```

This will pull and run the latest image from GitHub Container Registry.

### Manual Build and Run
1. Clone the repository:
```sh
git clone https://github.com/redrootdev/GoPrerender.git
cd GoPrerender
```
2. Build the Docker image:
```sh
docker build -t goprerender .
```
3. Run the container:
```sh
docker run -p 3000:3000 -e PORT=3000 -e CACHE_TTL=3600 -e TIMEOUT=20 goprerender
```

## Configuration

You can configure the service via environment variables:
| Variable | Description | Default |
|----------|-------------|---------|
| `PORT` | Port on which the service runs | `3000` |
| `CACHE_TTL` | Cache time-to-live in seconds | `3600` |
| `TIMEOUT` | Timeout for prerendering in seconds | `20` |
| `STABLE_MAX_CHECKS` | Max retries for stable HTML detection | `10` |
| `STABLE_INTERVAL` | Interval (seconds) between stability checks | `1` |
| `STABLE_MAX_CHANGE` | Maximum allowed changes before accepting HTML | `5` |
| `DOMAIN_WHITELIST` | Comma-separated list of allowed domains (`*` allows all) | `*` |

## API Usage

### Render a Page
To prerender a page, send a GET request:
```sh
curl "http://localhost:3000/render?url=https://example.com"
```

#### Response
```html

...
...

```

## Development
### Running Locally
1. Install dependencies:
```sh
go mod tidy
```
2. Run the application:
```sh
go run main.go
```

### Building the Binary
To build a standalone executable:
```sh
go build -o goprerender .
```

## Contributing
Contributions are welcome! Please open an issue or submit a pull request.

## License
This project is licensed under the [MIT License](LICENSE).