Hacker News new | ask | show | jobs
by olavk 2982 days ago
A typical example is "I want to keep my JavaScript code secret. How do I disable the 'View source' menu item in browsers?" This is a very frequently asked question. What would be the most helpful answer, if you imagine you are a newbie asking in good faith?

1) No answer

2) A technical explanation of how the 'view source' menu item can be suppressed (e.g. iframe, overriding right-click events and so on) which may at least work in some browsers some of the time.

3) An explanation why it is simply not technically possible to hide code sent over the wire to the client, and a suggestion to move sensitive code to the server if this is possible.

Clearly (2) is closest to the technically correct answer to the question... but it is it really helpful? Option (3) do offer unsolicited advice, which could be construed as condescending since this is not what was actually asked. But I will also argue this is the most useful response in 99% of cases.

But there might be some specific cases where (2) is actually relevant. E.g I'm building some kiosk-style console to provide an interactive quiz, and I don't want users to cheat by using view source to see the answers. In this controlled environment, it might be possible to completely disable "view source". So providing both (2) and (3) is the optimal answer, and should get the green checkmark.

But I simply fail to understand how giving no answer could be better for anybody?

1 comments

Parent said:

> If you can't answer it, or don't want to answer it

Here is how I would rank answers from best to worst:

1. Give the correct answer to the technical question asked, and some background about when to think twice about using it

2. Give the correct answer to the technical question asked

3. Why you should rethink the approach

4. No answer

5. "Don't do it"