Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pdf.js available on a cdn #5490

Closed
collinanderson opened this issue Nov 17, 2014 · 29 comments
Closed

make pdf.js available on a cdn #5490

collinanderson opened this issue Nov 17, 2014 · 29 comments

Comments

@collinanderson
Copy link
Contributor

Having pdf.js available on a public cdn can simplify installation and update workflows in some cases.

cdnjs will likely host pdf.js for free if was ask them to.

cdnjs/cdnjs#3824

@yurydelendik
Copy link
Contributor

please explain what problem it will fix. "because other projects do it" is a bad reason.

@yurydelendik yurydelendik reopened this Nov 17, 2014
@collinanderson collinanderson changed the title add to cdnjs make pdf.js available on a cdn Nov 17, 2014
@collinanderson
Copy link
Contributor Author

Good point. I updated the title and description.

@yurydelendik
Copy link
Contributor

pdf.js library is installable from npm using npm install pdfjs-dist, via bower install pdfjs-dist and simply via git pull from pdfjs-dist repo.

Having pdf.js available on a public cdn can simplify installation and update workflows in some cases.

What case is discussed here?

@collinanderson
Copy link
Contributor Author

In my workflow, I don't use npm or bowar or any tool for front-end dependency management and I prefer not to vendor copies of any library.

I instead link to a cdn-hosted version of jquery, jqueryui, ckeditor, or any other javascript library I need. Whenever I need to "upgrade", I simply change the version number in the url.

@yurydelendik
Copy link
Contributor

I instead link to a cdn-hosted version

Defects in browsers and CORS policies does not let users to instantiate web worker (pdf.worker.js file) that performs actual PDF parsing and significantly improves performance of the PDF.js.

There is an alternative: disable the worker. But that delivers sub-par performance and we don't want to advertise that.

@collinanderson
Copy link
Contributor Author

That's a good reason. Would be nice to get it CDN hosted if CORS ever allows it. Thanks!

@nschloe
Copy link
Contributor

nschloe commented Mar 23, 2015

I stumbled upon this when trying to use PDF.js in a jsfiddle.
fiddle

@joallard
Copy link

joallard commented Apr 6, 2015

Yup, mostly when using a prototyping tool without wanting to install a bunch of npm libraries locally

@luisrudge
Copy link

👍 for cdn support. Great for sharing bug repros and also quick prototyping

@lony
Copy link

lony commented Nov 2, 2015

Why there is still no CDN support as of November 2015?

@yurydelendik
Copy link
Contributor

Why there is still no CDN support as of November 2015?

AFIAK @cdnjs is publishing PDF.js (e.g. cdnjs/cdnjs#5993)

it is not this repository contributors initiative, so we are not aware if there is any issues present in relation with the published code.

@lony
Copy link

lony commented Nov 2, 2015

Sorry then, maybe it is vice to add the URL to the ReadMe to avoid further questions?

@yurydelendik
Copy link
Contributor

Sorry then, maybe it is vice to add the URL to the ReadMe to avoid further questions?

Only when we will verify that it works without issues or security risks. See my concern above at #5490 (comment)

@lony
Copy link

lony commented Nov 2, 2015

Sorry then :)

@camitz
Copy link

camitz commented Dec 30, 2015

My use case requires complete transparency. Performance is entirely subordinate. That's why I use pdf.js because I want nothing hidden away on a server. Everything is done on the client, the code is guaranteed to do what it claims it does.

My own code is small, easy to read and open for scrutiny. Never minified even in production. I rely on third-party code that runs on the client, and the trust stems from the authors and the open source community. The app is open source on git hub and the app itself is even hosted on git hub.

As long as the app is kept this way, my credibility is not important. However, if I include pdf.js in the source, even if it is not built or minified, that seriously degrades transparency. The user needs to have faith in me that I have not hidden malicious code in the pdf.js jungle.

On the other hand, if pdf.js and all other third-party code, were fetched (preferably unminified) from a cdn endorsed by the team and community, my own credibility becomes nearly irrelevant.

@yurydelendik
Copy link
Contributor

With wrapped for the worker (see #6753), the core library is "hostable" on CDN, e.g. minimal example that works fine on the jsfiddle and jsbin:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Minimal PDF.js example</title>
  <script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
</head>
<body>
  <script>
    var loadingTask = PDFJS.getDocument('//cdn.mozilla.net/pdfjs/tracemonkey.pdf');
    loadingTask.promise.then(function (pdfDocument)  { 
      console.log('Num pages: ' + pdfDocument.numPages);
    }, function (reason) {
      console.error('Loading Error: ' + reason);
    })
  </script>
</body>
</html>

@darylteo
Copy link

NPM CDN hosts all npm packages on request.

https://npmcdn.com/pdfjs-dist@1.4.79/build/pdf.combined.js

Obviously not maintainer sanctioned, but it's there if people want it for prototyping purposes.

@camitz
Copy link

camitz commented Feb 18, 2016

@yurydelendik That will definitely work for me, thanks!

@darylteo Thanks for the tip. Not as transparent though, which is the which would be the whole point for me.

@yurydelendik
Copy link
Contributor

https://npmcdn.com/pdfjs-dist@1.4.79/build/pdf.combined.js

@darylteo, PDF.js team is always thinking about deprecating pdf.combined.js since it is not intended use of the library. Please try to not use it when it's possible (as well as do not apply disableWorker=true, which pdf.combined.js implies).

@darylteo
Copy link

@yurydelendik thanks for the info! I'm just building a prototype to workaround iOS WKWebView not rendering PDFs properly in iframes for the time being but will keep that in mind.

@jon-freed
Copy link

@camitz , I'm curious. How or why did yurydelendik's Feb 8 code "work for [you]"? I am asking because it references //mozilla.github.io/pdf.js/build/pdf.js, and I wouldn't generally view that as a cdn. And, it also isn't referencing a versioned copy of pdf.js

@yurydelendik (or whomever is appropriate) - can this issue please be reopened until versioned and minified copies of pdf.js are definitely available on at least one reputable cdn? This issue started with a reference to cdnjs, and as per their website, they now have a preferred way to "Request a lib" via a [GitHub issue template](https://github.com/cdnjs/cdnjs/issues/new?title=%5BRequest%5D Add library_name &body=Library name%3A %0AGit repository url%3A%0Anpm package url%28optional%29%3A %0ALicense%28s%29%3A%0AOfficial homepage%3A%0AWanna say something? Leave message here%3A%0A%0A=====================%0ANotes from cdnjs maintainer%3A%0APlease read the README.md and CONTRIBUTING.md document first.%0A%0AYou are welcome to add a library via sending pull request%2C%0Ait%27ll be faster then just opening a request issue%2C%0Aand please don%27t forget to read the guidelines for contributing%2C thanks!!) for requesting that PDF.js is added to cdnjs. Would a PDF.js project leader please make such a request? (I would do it myself but I don't know whether the PDF.js project would want cdnjs to use pdf.js or pdfjs-dist. Also, it would probably be best if the PDF.js project itself created a minified version of its code that goes to cdnjs.)

I think that camitz's use case that he shared on Dec 30 is very good and still applicable for lots of people (including myself). Like camitz, I would like to minimize the amount of trust that my users have to put in me, and using copies of libraries that are on a CDN definitely helps with that.

@timvandermeij
Copy link
Contributor

@jon-freed There is https://npmcdn.com/pdfjs-dist which is up-to-date. For cdnjs there is the pull request cdnjs/cdnjs#5993. I don't think there is more we can do at this point; especially the npmcdn website is nice because it uses our NPM package and is therefore always up-to-date.

@yurydelendik
Copy link
Contributor

@jon-freed here is jsfiddle example that uses npmcdn https://jsfiddle.net/y3rsLwwp/5/

@jon-freed
Copy link

@timvandermeij , @yurydelendik : Thank you for that information! That helps clarify (to me, anyhow) what darylteo stated on Feb 17

@PeterDaveHello
Copy link
Contributor

hmmmm ... CDNJS maintain here, I'll work on it now.

@PeterDaveHello
Copy link
Contributor

Okay, now added in: cdnjs/cdnjs@df40a0d

@PeterDaveHello
Copy link
Contributor

@timvandermeij
Copy link
Contributor

@PeterDaveHello Awesome! Good to have PDF.js hosted on two CDNs (cdnjs and npmcdn) now.

@PeterDaveHello
Copy link
Contributor

PeterDaveHello commented Jun 18, 2016

No probs. Just FYI, by the architecture, npmcdn may update a little bit faster, but CDNJS will have better performance for production environment, and CDNJS also provides minified files and additional map files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests