Free Open Source Cookie Guard v3.0.0
A simple, customizable and ultra-lightweight cookie consent manager that handles the heavy lifting of GDPR and CCPA compliance. Pure vanilla JavaScript. 22 languages. 12.7 kB. No dark patterns. No jQuery. No headaches.Cookie Consent Made Simple. Compliant by Design.
Cookie Guard handles GDPR and CCPA compliance so you don't have to. It manages user consent, controls third-party scripts, and respects privacy—all in a lightweight, zero-dependency package. Pure vanilla JavaScript. No jQuery. No external libraries. Just 12.7 kB of clean, tested code.
One Tool. Two Modes. Total Compliance.
Cookie Guard works for any website — whether you use third-party scripts or not. Consent mode (consent: true) manages analytics and marketing scripts with full user approval. Perfect for sites using third-party analytics, social media pixels, or any third-party services. Info mode (consent: false) displays a simple informational banner without blocking scripts. Ideal for sites that don't use third-party cookies but still need to inform users about privacy practices. In both modes, Cookie Guard informs your users about your cookie policy — ensuring you're fully compliant with GDPR and CCPA requirements. One tool. Both modes. Your choice.
Supported Languages
22 languages with LTR & RTL support: English, Spanish, Catalan, Basque, Galician, Estonian, Arabic, Portuguese, Polish, Vietnamese, French, German, Italian, Russian, Chinese, Japanese, Indonesian, Korean, Turkish, Dutch, Hindi, Bengali.

Key Features
- Legal Compliance — Fully GDPR/CCPA compliant workflow (2026 standards).
- Hybrid Modes — Full third-party consent or informational "no-cookies" mode.
- Smart Execution — Auto-activates Analytics/Marketing scripts.
- Zero Dependencies — Pure vanilla JavaScript. No jQuery. No external libraries.
- 22 Languages — LTR & RTL support with automatic browser detection.
- Privacy Focus — Optional persistent privacy button to re-open settings.
- Ultra-Lightweight — 12.7 kB minified. Fast. No bloat.
- Accessibility — Implements ARIA standards for screen readers.
Installation
Add the minified version before the closing </body> tag:
Important: If you're fetching the script from a remote location, include integrity and crossorigin="anonymous" to ensure security and prevent tampering.
<script
src="https://opensource.josebamirena.com/cookie-guard/3.0.0/dist/cookie-guard.min.js"
integrity="sha384-4TomZ6aXKNjC0fGi+v+GQTBp9kmS006nQ3SriGo6U0a93lhADVwmw8toL8JQW4vB"
crossorigin="anonymous">
</script>Basic Initialization
<script>
document.addEventListener('DOMContentLoaded', () => CookieGuard.init());
</script>Custom Configuration
Note: You can set a specific language or use auto mode — Cookie Guard will automatically detect and use your user's preferred language.
<script>
document.addEventListener('DOMContentLoaded', () =>
CookieGuard.init({
locale: 'en', // fixed language
url: '/legal', // legal page URL
link: '#ff0000', // link color
radius: 8, // button border radius
consent: true // third-party cookies mode
})
);
</script>Configuration Options
Note: When a legal URL is provided, Cookie Guard suppresses the modal on that page and handles legal terms acceptance automatically.
| Property | Type | Default | Description |
|---|---|---|---|
| locale | string | auto | 'auto' or 2-letter language ISO code |
| consent | boolean | true | true for 3rd party scripts, false for info-only banner |
| url | string | null | Relative URL to your legal/cookies policy page |
| reopen | boolean | true | Renders the floating privacy button |
| radius | integer | 12 | Buttons border-radius in pixels |
| delay | integer | 800 | Modal entrance delay in milliseconds |
| link | string | #3b82f6 | Primary link color |
| hover | string | #10b981 | Link hover color |
| separator | string | • | Modal footer links separator |
| expiration | integer | 365 | Consent cookie expiration in days |
Script Implementation
Note: To let Cookie Guard manage your scripts, add the type attribute text/plain and add the data-cg-category attribute:
<script
type="text/plain"
data-cg-category="analytics"
src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXX-Y">
</script>
<script type="text/plain" data-cg-category="marketing">
console.log("Facebook pixel is legally enabled.");
fbq('init', '123456789');
fbq('track', 'PageView');
</script>Developer API
- Toggle Modal —
CookieGuard.toggle() - Force Open —
CookieGuard.open() - Hard Reset —
CookieGuard.reset() - *Reset shortcut: CTRL + SHIFT + X
Download Cookie Guard v3.0.0 Files
Important: Please do not fetch files directly from this website. Remote fetching is blocked for security and performance reasons.
Follow the instructions and use my opensource CDN.
- cookie-guard.min.js— Minified javascript code
12.7 kB. CHECKSUM: 6c9a099d5675772a1a102e50de5c096b - cookie-guard.js— Source javascript code, unminified
26.3 kB. CHECKSUM: 96d3906a38b63d06b3489d25f7dec7de - cookie-guard-3.0.0.zip— Complete package with docs & languages
42.3 kB. CHECKSUM: 285241e42d141e329c1aaf804a7a697e - README— MD format documentation
- LICENSE— MIT license
All Freebies are open source under the MIT License. Free for personal and commercial use. A link back is appreciated but never required.
