<script src="https://cdnjs.cloudflare.com/ajax/libs/sanitize-html/1.27.5/sanitize-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.2.7/purify.min.js"></script>
const testString = `
<b>Welcome to safeland</b><br>
<a href='javascript:alert(1)'>This is fun</a><br>
<img src=x onerror=console.log(1)>
`
const result = DOMPurify.sanitize(testString)
const testString = `
<b>Welcome to safeland</b><br>
<a href='javascript:alert(1)'>This is fun</a><br>
<img src=x onerror=console.log(1)>
`
const result = sanitizeHtml(testString)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
DOMPurify | |
Sanitize HTML |
Test name | Executions per second |
---|---|
DOMPurify | 25967.2 Ops/sec |
Sanitize HTML | 134564.8 Ops/sec |
Benchmark Overview
MeasureThat.net is a platform that allows users to create and run JavaScript microbenchmarks. The provided benchmark compares the performance of two popular libraries: DOMPurify and sanitize-html.
Library Descriptions
Comparison of Options
The benchmark compares the performance of two options:
Pros and Cons of Each Approach
Special JS Features/Syntax
In this benchmark, the test users special JavaScript features/syntax:
onerror
attribute of an image tag.Other Considerations
Alternatives
If you're interested in exploring alternative libraries or approaches for sanitizing HTML content, some popular options include:
Note that the choice of library or approach depends on your specific use case, performance requirements, and level of control over sanitization logic.