Agile Ruby on Rails and iOS Development from Berlin

Disable console.log in production

You know the problem – sometimes you just forget one console.log statement in your JavaScript and have console logs in production mode or even worse – the script is completely broken on IE. Here I describe a way how you can be sure that console is defined and quiet in production mode:

Define a HTML5 data-atribute in your applictaion.html.haml:

  %body{data-env: Rails.env}

Second step is to include this javascript snippet, which checks – after the DOM is loaded – if we are in production mode or if console is undefined. If so, we define console.log as an empty function.

  if ($('body').data('env') == 'production' || typeof console == "undefined"){
    var console = { log: function() {} };

Warning: file_get_contents( [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /srv/www/wordpress/wp-content/themes/airship/footer.php on line 23