nopaste icon indicating copy to clipboard operation
nopaste copied to clipboard

cdn dependency

Open rnwgnr opened this issue 3 years ago • 16 comments

I just came across NoPaste. The concept of not "storing" the data at all seems very appealing to me.

Relaying on external CDNs to ship most of the required files seems counter-intuitive to me.

Have you ever considered creating a deployable package which includes the dependencys so that they are shipped from the local host?

rnwgnr avatar Oct 06 '20 18:10 rnwgnr

Hi,

That is not a bad idea at all,

My only requirement for this project is that everyone should be able to use the files from the git repository immediately, without having to build anything.

Maybe I could bundle all the dependencies into a single file, and add it to the source files, maybe using webpack? I'll try to do something

bokub avatar Oct 08 '20 11:10 bokub

My only requirement for this project is that everyone should be able to use the files from the git repository immediately, without having to build anything.

Fair enough.

Maybe I could bundle all the dependencies into a single file, and add it to the source files, maybe using webpack? I'll try to do something

Sounds good. :+1:

rnwgnr avatar Oct 09 '20 18:10 rnwgnr

@bokub Any news? I just started hosting an instance on PussTheCat.org ( https://nopaste.pussthecat.org/ ) and it's one of my only complaint with it. If you don't do it, I'll surely fork the project and do it.

TheFrenchGhosty avatar Nov 28 '21 16:11 TheFrenchGhosty

Well, I couldn't manage to do that in an elegant way.. 🤷🏻‍♂️

Feel free to submit a PR, I'm curious to see what can be done, but I think the easiest way to get rid of the CDN is just to download the files and host them yourself.

bokub avatar Nov 28 '21 16:11 bokub

@bokub If I do it, I'll just do it "the easy way": download the files served by the CDNs, and serve them internally (similar to how I fixed the namazso.eu website: https://github.com/namazso/namazso.eu/pull/2

TheFrenchGhosty avatar Nov 28 '21 16:11 TheFrenchGhosty

Yeah that's the easiest thing to do.

For NoPaste, it's just one css file and one js file.

bokub avatar Nov 28 '21 16:11 bokub

@bokub Okay so I started doing it, and I am currently stuck: I don't know what to do to remove this call, since it's calling multiple scripts: https://github.com/TheFrenchGhosty/nopaste/blob/master/scripts/script.js#L19

Also, it's currently broken for whatever reason: https://github.com/TheFrenchGhosty/nopaste

TheFrenchGhosty avatar Dec 14 '21 14:12 TheFrenchGhosty

In the current code, if I replace %N with css, the URL will point to https://cdn.jsdelivr.net/npm/[email protected]/mode/css/css.js which contains the code for CSS syntax highlighting. It's the CDN version of this file.

If you want to serve the modes yourself, you need to download and host every .js file of the ./mode folder of CodeMirror (https://github.com/codemirror/CodeMirror/tree/5.58.1/mode), if possible at tag 5.58.1, then edit the URL so it points to your files (%N being a placeholder for the mode name).

bokub avatar Dec 14 '21 14:12 bokub

@bokub Alright, I finally have all resources loaded internally, however it's still broken and I don't know why, any idea?

Edit:

Those are the errors:

s

Edit 2:

Here a PR if you want to fix it: https://github.com/bokub/nopaste/pull/8

TheFrenchGhosty avatar Dec 14 '21 15:12 TheFrenchGhosty

It's "broken" because you forgot to include CodeMirror...

image

bokub avatar Dec 14 '21 16:12 bokub

@bokub Oh I completely missed that!

So this fixed it, but it's now complaining about not being able to load the compression library:

1 2

I tried various path but I couldn't make it to work, any idea?

TheFrenchGhosty avatar Dec 14 '21 16:12 TheFrenchGhosty

You need to provide the whole URL, not just "./scripts/lzma_worker.js"!

Otherwise, I think you can replace the first lines of script.js with this (I'm not 100% sure tho):

- const blob = new Blob(['importScripts("https://cdn.jsdelivr.net/npm/[email protected]/src/lzma_worker.min.js");']);
- const lzma = new LZMA(window.URL.createObjectURL(blob));
+ const lzma = new LZMA("./scripts/lzma_worker.js");

bokub avatar Dec 14 '21 16:12 bokub

@bokub And it's working! Thanks a lot!

TheFrenchGhosty avatar Dec 14 '21 16:12 TheFrenchGhosty

One last issue (it's working perfectly so I don't know if it maters or not):

s

TheFrenchGhosty avatar Dec 14 '21 16:12 TheFrenchGhosty

It's because you're opening the files directly with your browser (file:///) instead of using a file server, which would be accessible on http://localhost

bokub avatar Dec 14 '21 17:12 bokub

@bokub Ah, that's good to know!

Thanks for the help :)

TheFrenchGhosty avatar Dec 14 '21 17:12 TheFrenchGhosty