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.

Free Open Source Cookie Guard v3.0.0

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.

PropertyTypeDefaultDescription
localestringauto'auto' or 2-letter language ISO code
consentbooleantruetrue for 3rd party scripts, false for info-only banner
urlstringnullRelative URL to your legal/cookies policy page
reopenbooleantrueRenders the floating privacy button
radiusinteger12Buttons border-radius in pixels
delayinteger800Modal entrance delay in milliseconds
linkstring#3b82f6Primary link color
hoverstring#10b981Link hover color
separatorstringModal footer links separator
expirationinteger365Consent 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 ModalCookieGuard.toggle()
  • Force OpenCookieGuard.open()
  • Hard ResetCookieGuard.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.

Free Open Source Cookie Guard v3.0.0

GDPR/CCPA compliant. Lightweight. Zero dependencies.

Free Tools: What to Know

If you need anything, don't hesitate to contact me—I'm always happy to help!

Do I need to sign up to use these tools?

No. Never. Not happening. There is no hidden 'cost'. These are genuinely free.

I don't ask for emails. I don't ask for signups. Click, copy, use. That's it. I built these for myself and I'm sharing them because sharing is how we all grow.

How should I host these tools?

You can download and host them yourself, or you can use my opensource CDN.

Please do not fetch files directly from this website—remote fetching is blocked for security and performance reasons.

What license are these tools under?

These are free, open source, and MIT licensed. Free for anything.

Personal use. Commercial use. Modify it. Sell it. Whatever works for you. All I ask? If you find it useful, a link back to this site is appreciated. But it's not required. Ever.

Can I modify the code?

Absolutely. It's yours now.

Take it. Modify it. Break it. Fix it. Use it in your projects. Share it with your friends. I built this to be useful, not to be protected. Just don't sell it as your own—that's not cool.

Will these tools be maintained?

Yes, I use them myself—you can see them on this website and across many client projects.

These tools aren't abandoned. I use them in my own apps, so they stay updated, tested, and working. If something breaks, I'll fix it—because I need it too. You can visit this page to stay updated with new versions and improvements.

Can I request a tool?

Maybe. If it sparks my curiosity and/or adds value to me or my clients.

If you need something I haven't built yet, let me know. If it catches my interest, I might build it. If not? You still got free code. No loss.

AntiFraud Expert

Stopping the fraudsters before they strike.

Contact AntiFraud Expert
more

Recommended Products

🔺Joseba Mirena has no involvement in any of the recommended products; all brands are property of their respective companies.
*Sponsored product selection. As an Amazon Associate, I earn from qualifying purchases. These affiliate links do NOT add any additional cost to the customer.
*Prices and reviews are indicative and subject to change without prior notice.

Joseba Mirena

Online Business Developer

Let's boost your business.

Powered by Google™
Powered by Debian™
Powered by Nginx™
Powered by PHP™
Powered by Amazon AWS™
Code That Scales. Teams That Thrive. Security That Protects.