Simple cross-browser cookie consent plugin written in plain javascript

Cookie Consent

Simple cross-browser cookie consent plugin written in plain javascript.

Why though

I wanted a simple, lightweight but also “extensible” plugin, which could be placed in my own web server without the need of making additional external requests. The reason was to further optimize the loading speed of my website.

Main features

  • Cross-browser support (IE8+)
  • Standalone (no external dependecies needed)
  • Lightweight (~ 8kb for optimized/minified version)
  • Can easily add support for additional languages
  • Automatic browser language detection
  • No additional external http requests

How to run

  • Include file (or load it dynamically)

     <script src="<your_path>/cookieconsent.js"></script>
  • Initialize cookieconsent (with default config. settings)<config_object>);
  • Show cookieconsent modal (will show only if cookieconsent was not alredy accepted)<optional_delay_value>);
  • Hide cookieconsent modal (if it is attached to dom)


Custom config. settings

Another way is to run the cookieconsent with an initial config object like in the example below.{
	"cc_autorun" : false, 						
	"cc_delay" : 0,								
	"cc_website_name" : "Orest Bida",
	"cc_website_url" : "",				
	"cc_enable_verbose" : true,					
	"cc_current_lang" : "en",	
	"cc_auto_language" : false,					
	"cc_theme_css" : "<your_path>/cookieconsent.css"

Config. properties

  • cc_autorun : (boolean)
    • default : false
    • if set to true, cookieconsent will show modal as soon as loaded
  • cc_delay : (number)
    • default : 0
    • if specified (>=0), there will be an initial delay before showing the cookieconsent modal
    • useful when you have implemented a “loader”
  • cc_enable_verbose : (boolean)
    • default : true
    • if set to true, all informational/error messages will show on console
  • cc_current_lang : (string)
    • default : “en”
    • when specified, modal will be set to that language (if it is implemented)
  • cc_auto_language : (boolean)
    • default : false
    • if set to true, cc_current_lang will be ignored, and the cookieconsent modal will set its language based on client browser language (if specific client browser language is not defined, a fallback_language=“en” will be used instead)
  • cc_theme_css : (string)
    • default : null
    • specify path to local cookieconsent.css file


List of things to implement

  • Add the possibility of “quickly” defining a new language without the necessity of directly editing source file
  • Make cookieconsent GPDR compliant:
    • Implement “learn more” modal with a brief explanation about cookies
    • Implement custom-cookie-table containing:
      • column for cookie-name
      • column for cookie-description
      • column for cookie-expiration-date
    • Implement the (eventual) possibility of opting-out of cookie-consent

Download Details:

Author: orestbida

Source Code:


Simple cross-browser cookie consent plugin written in plain javascript
15.70 GEEK