A few years ago, it stopped working on Youtube. I increased the limit to 32kB, as I figured it would give a safe margin.
Well, it broke again some time this month:
>>> import urllib.request
>>> urllib.request.urlopen('https://www.youtube.com/watch?v=dQw4w9WgXcQ').read().index(b'
This seems to be mostly inlined minified Javascript. Why does Youtube do this instead of including scripts that could be cached?As for why someone would embed JavaScript directly on page instead of via a script, usually you want that piece of code to run as soon as possible when the user opens the code. Including scripts that gets loaded over network can get loaded much later compared to when you inline it.