Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
102
rated 0 times [  103] [ 1]  / answers: 1 / hits: 83290  / 13 Years ago, thu, november 3, 2011, 12:00:00

I currently have this JS statement everywhere in my code:



window.console && console.log(Foo);


I am wondering if this is costly at all, or has any negative side-effects in production.



Am I free to leave client-side logging in, or should it go?



EDIT: In the end, I suppose the best argument I (and anyone else?) can come up with is that there is a possibly non-negligible amount of extra data transferred between the server and the client by leaving logging messages left in. If production code is to be fully optimized, logging will have to be removed to reduce the size of javascript being sent to the client.


More From » logging

 Answers
66

You should not add development tools to a production page.



To answer the other question: The code cannot have a negative side-effect:




  • window.console will evaluate to false if console is not defined

  • console.log(Foo) will print the message to the console when it's defined (provided that the page does not overwrite console.log by a non-function).


[#89310] Wednesday, November 2, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myrap

Total Points: 407
Total Questions: 105
Total Answers: 109

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
myrap questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Wed, Jan 15, 20, 00:00, 4 Years ago
Thu, Oct 24, 19, 00:00, 5 Years ago
Thu, Oct 3, 19, 00:00, 5 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;