-3

I know that I can call a javascript function on keyup in a input box. but is there any way to refresh a javascript file on keyup in my input box?

I dowloaded prettify. I am creating a page just like stackoverflow's ask a question page. As we know the text in the preview box gets updated whenever we type something. I could replicate this with jquery and ajax. But in the code parts prettify does not work. However when i have code when the page loads, it works.

I suppose that reloading the prettify js file everytime i enter something will make it work.. please help

user1763032
  • 427
  • 9
  • 24
  • You shouldn't be reloading your scripts. You should remove the tags that prettify adds and then rerun the function that "prettifies" your text. This post might help: http://stackoverflow.com/questions/16014494/prettyprint-only-has-an-effect-once-google-prettify – Juan Carlos Farah Jul 16 '14 at 10:25
  • reloading a javascript file every time you enter something would completely ruin client-side performance. And even auto-prettifying your input every time you enter something would be a severe performance trap. For reference, a user typing at 300 strokes per minute would have 5 javascript calls per second, which gets heavy really fast. If you want to do provide a prettifier, add a button on your page that the user can use themselves when they need it. – Nzall Jul 16 '14 at 10:26

2 Answers2

1

You should not try to approach this by reloading any scripts. That's a really dumb idea, it's like the polar opposite of what you should do.

See if there is some kind of method in prettify.js that you can call when you want to re-prettify code parts.

Swiffy
  • 4,401
  • 2
  • 23
  • 49
0

I'm not entirely sure that I understand your question - it is unclear whether the file you want to reload actually changes contents?

I have had experience reloading a file, which was being cached by the browser. to avoid the browser cache, simply add a parameter to your URL

ie: if you want to reload http://www.example.com/myjs.js then call http://www.example.com/myjs.js?id=1234 (where 1234 is a timestamp, or counter, basically something different every call)

while it isn't pretty, it works.

JoSSte
  • 2,953
  • 6
  • 34
  • 54