11

I sometimes see questions with a link to a runnable code site like CodePen or JSFiddle that contains some complicated computation of the resulting page. Currently, the worst are tools like CodeSandbox, where complete SPAs can be shown off.

Questions often enough are just about the markup or CSS of the rendered result, so the programmatic part is completely irrelevant. If the OP is aware of that fact, they might be even willing to provide a simplified stack snippet, if they just knew how to.

Can this be achieved without too much additional knowledge?

5
  • 4
    For some reason, when I saw this title, I had the intuition it was going to be a self-answered question before opening it.
    – BoltClock Mod
    Commented Nov 6, 2020 at 16:46
  • 1
    @BoltClock Probably because it's currently phrased as a statement rather than a question
    – TylerH
    Commented Nov 6, 2020 at 20:07
  • And that is because I first thought to post this as an answer to another question, and only then thinking again.
    – ccprog
    Commented Nov 6, 2020 at 20:15
  • @TylerH I changed that without reading the comments. Meh, I guess it should be with a comment.
    – 10 Rep
    Commented Nov 6, 2020 at 21:01
  • @10Rep It's probably fine either way.
    – TylerH
    Commented Nov 6, 2020 at 21:04

1 Answer 1

10

A sensible way to obtain a minimal example to provide in the post might be this:

  1. Run your code in CodePen, JSFiddle or CodeSandbox, or wherever you try your code.

  2. Open the developer tools by pressing F12. In the Elements (Chrome) / Inspector (Firefox) tab, select the outermost element of the result that will show your problem. You can start that with the element picker, an icon in the upper left corner of the developer tools.

  3. If your choice doesn't fit in the first attempt, try to choose another element (most probably a parent) in the shown element tree, until you are happy with your choice.

  4. Right-click on that element in the tree and select "Copy Outer HTML".

  5. In your question, open the snippet editor and paste to the HTML cell. Please format the code.

  6. In JSFiddle, copy your CSS and paste it to the CSS cell in the snippet editor.

  7. Now, try to slim down your code further, especially delete the irrelevant CSS parts.

It might be worth to notice that others could be reluctant to do this job for you, as they might infringe on copyright. You are certainly in a better legal position if it is you that decides which code goes on Stack Overflow.

7
  • 8
    Suggestion: A note that only the OP can move code that's only on a 3rd party site like jsFiddle to Stack Overflow because their copyright licenses are incompatible. Your answer already reads like it's addressing the OP but it might not hurt to be explicit.
    – BSMP
    Commented Nov 5, 2020 at 18:41
  • I would not subscribe to that. I have actually, in cases I thought it would benefit the question, edited them to include code that had been posted externally. And I never got complaints from the OP about that. To the contrary, they were probably content that I took the time to improve their question. And for a 20 line code example, I would not worry toomuch about copyright.
    – ccprog
    Commented Nov 5, 2020 at 19:37
  • 7
    ccprog you might not worry too much, but given the recent developments within the SE company, including the relicensing, they very much do worry. I'm with @BSMP therefore to be explicit that only the OP can verify whether the license allows them to post their code on SO (or anywhere else). I agree that it is unlikely to be a big issue or that many OPs actually will care/check, but it's best to simply avoid potentially running into trouble.
    – Adriaan
    Commented Nov 6, 2020 at 10:24
  • 1
    related: meta.stackoverflow.com/questions/344484/…
    – rene
    Commented Nov 6, 2020 at 10:50
  • You are right, I was arguing from the standpoint of a non-US legal system, which would not help.
    – ccprog
    Commented Nov 6, 2020 at 14:59
  • 2
    This answer makes a lot of assumptions about the capabilities and willingness of most new users on SO nowadays.
    – Ian Kemp
    Commented Nov 6, 2020 at 17:07
  • 1
    @IanKemp Giving advice is not assuming that everyone will follow it.
    – khelwood
    Commented Nov 6, 2020 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .