Where should a compiled script be placed in React?

157 Views Asked by At

I am trying to include client side library (OpenPGP.js) in my react application to allow multiple react components to interact with OpenPGP.js via utility functions. Where should I place the script tag <script src="https://cdnjs.cloudflare.com/ajax/libs/openpgp/2.5.11/openpgp.js"></script>? Also, where should I write my utility functions (as shown in https://github.com/openpgpjs/openpgpjs#examples) such that they are accessible to all my components?

1

There are 1 best solutions below

7
On BEST ANSWER

Why don't you consider using npm install --save openpgp?. If you are you using npm for your project?

Then you can import it in any component like below

import openpgp from 'openpgp';

and use it like below.

openpgp.initWorker({ path:'openpgp.worker.js' });