react-prism icon indicating copy to clipboard operation
react-prism copied to clipboard

Prism.js loaded every time the component renders

Open alejandrodnm opened this issue 10 years ago • 5 comments

Trying the library and seeing the github example, every time a new PrismCode renders a request is made for the prism.js library.

Is there any way to load it only once?

Thanks

alejandrodnm avatar Aug 28 '15 09:08 alejandrodnm

I believe it's due to their WebWorker API. Would you look at their docs too?

tomchentw avatar Aug 28 '15 15:08 tomchentw

@tomchentw do you think worker-loader for webpack helps to have Prism be loaded w/ commonsJS? https://github.com/webpack/worker-loader

chibicode avatar Apr 23 '16 23:04 chibicode

@chibicode I think so. You can load Prism that way and use expose loader in conjunction with it to make Prism globally accessible. In that case, you don't need to import Prism from a separate script tag.

Feel free to open a PR for updating these steps on README.md. Thanks!

tomchentw avatar Apr 26 '16 02:04 tomchentw

Any update on this @chibicode @tomchentw?

schickling avatar Aug 19 '16 10:08 schickling

@schickling could you try the latest example that's loading prism from cdn (not webpack)? https://github.com/tomchentw/react-prism/blob/cde34385be8ac5792d6974c115d2b731a8ce58c5/index.html#L11

tomchentw avatar Sep 22 '16 11:09 tomchentw