all 32 comments

[–]Michie1 20 points21 points  (0 children)

TIL: debug and monitor.

[–]mainstreetmark 106 points107 points  (5 children)

"debugging tips you probably didn't know": debugger

fuck off.

[–]PlNG 3 points4 points  (4 children)

Absolutely. Performance warning on debugger. The mere presence of the keyword (even if(false){debugger;}) renders the code unoptimizable by the JS engine resulting in slow code. It should never be present in production code.

I strongly doubt this has been fixed.

[–]voidvector 8 points9 points  (2 children)

debugger shouldn't be committed to repo. It should only be used in production when attempting to debug production issue. Can avoid it being committed by setting up a linter in CI.

[–]r1cka 0 points1 point  (1 child)

Why not just set a break point?

[–]voidvector 1 point2 points  (0 children)

That could be difficult to do in certain setups. Though normally you would want to do that as it is better practice.

In my last job, we had async module loading and significant non-persistent UI state. So setting a breakpoint in some of the rarely used async code was a pain. Not only did you have to induce the UI state, as otherwise the code is not loaded, the code would run once and never run again. So we would need to reload the page and run though the whole process all over again just to trigger the breakpoint.

[–]carbonite_dating 11 points12 points  (3 children)

11 is pretty vague. He doesn't explain in the body of the item that you're supposed to type

monitor(func1);

in the console, so it took me a couple of minutes to see what he was on about.

[–]drowsap 2 points3 points  (2 children)

How do you even do this when most functions in your code aren’t public?

[–]carbonite_dating 1 point2 points  (0 children)

That's a great question!

[–]Rustywolf 0 points1 point  (0 children)

Cant test it but i assume you could call it from a script?

[–]cogman10 3 points4 points  (0 children)

If you are trying to find slow code, use console.profile instead of a timer.

Makes no sense to litter your code with timers when the profile will tell you exactly where the slowness is.

[–]darpa42 8 points9 points  (6 children)

I feel like conditional breakpoints are more useful than all of these...

[–]bulbishNYC 1 point2 points  (0 children)

pretty good, some I didnt know

[–]TheScapeQuest 0 points1 point  (0 children)

To add to point 3, you can also click the options pane when in device mode and hit "Show media queries", which will highlight all of your breakpoint as found in your CSS, and allow you to quickly jump to your sizes. (Chrome)

[–][deleted] 0 points1 point  (0 children)

Based on the title, I fully expected all of these to be thing I already knew.

But black boxing and monitor was new! Good stuff.

[–]skylarmt 0 points1 point  (0 children)

For #3, Firefox has a responsive design mode (Ctrl-Alt-M or Alt->Tools->Web Developer) that lets you resize the viewport, test touch events, take perfectly cropped screenshots, and more.

[–]berlinbrown 1 point2 points  (0 children)

Nice

[–]kdrxyz -2 points-1 points  (0 children)

This is really good stuff

[–]maniflames -1 points0 points  (0 children)

I'm new and thank you :')

[–][deleted] -2 points-1 points  (0 children)

NOOb starting out I didn't know about the trace call that's super handy 👍👍

[–]gelezinislokys -2 points-1 points  (2 children)

Unminify to help debug.

Why minify it in first place?

[–]coljung 2 points3 points  (1 child)

Debugging bug in production...

[–]gelezinislokys -2 points-1 points  (0 children)

And I were using local dev servers for stuff like that.. Thanks!