hugo-embed-pdf-shortcode
hugo-embed-pdf-shortcode copied to clipboard
PDF not loading on Netlify but is OK on localhost
Describe the bug A clear and concise description of what the bug is. When I upload my site to Netlify the spinner keeps on spinning but at the localhost it loads in a very short time.
To Reproduce Steps to reproduce the behavior: Open page with the "hugo-embed-pdf-shortcode"
Expected behavior A clear and concise description of what you expected to happen. I expect to see the PDF file
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Ubuntu 23.04
- Browser [e.g. chrome, safari]
- Brave browser, Firefox, Chrome
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context Add any other context about the problem here. I had installed it and the problem started where it was not loading on Netlify and had stopped loading on localhost. I then reinstalled it and it started reloading in localhost but not on Netlify. I think I have read of other people having this problem with Netlify but I didn't see any solutions to the problem.
Hi @GerBreOwn . Could you please share a link to your repository and the file where you are trying to embed the pdf.
gerbreown/epghoa is my github repository. The file is /content/Minutes/feb-26-minutes. When I look at your file "pdf.worker.js" I do not find any lines with "GlobalWorkerOptions" in them especially at line 124 like your instructions state. Thanks.
gerbreown/epghoa is my github repository. The file is /content/Minutes/feb-26-minutes. When I look at your file "pdf.worker.js" I do not find any lines with "GlobalWorkerOptions" in them especially at line 124 like your instructions state. Thanks.
Let me take a look and get back to you.
@GerBreOwn I am unable to find this repository https://github.com/gerbreown/epghoa. Is it a private repo by any chance?
I am also seeing this issue, things work fine locally but I am getting a 404 https://<SomeURL>.github.io/js/pdf-js/build/pdf.js
when trying to access pdf.js
. I installed hugo-embed-pdf-shortcode via the git submodule commands. I am using Github pages if that isn't clear. Are there any trouble shooting actions that are suggested? Thanks!
Hi I m seeing the same issue, it works on localhost, it does not work on live. I host my website in aws s3. I can download the pdf file, it just keeps loading without showing. In console I get the errors:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED pdf.worker.js:1
Uncaught (in promise) Error: Setting up fake worker failed: "Cannot load script at: https://<website-domain>js/pdf-js/build/pdf.worker.js". at api.js:2219:11
Hi I m seeing the same issue, it works on localhost, it does not work on live. I host my website in aws s3. I can download the pdf file, it just keeps loading without showing. In console I get the errors:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED pdf.worker.js:1 Uncaught (in promise) Error: Setting up fake worker failed: "Cannot load script at: https://<website-domain>js/pdf-js/build/pdf.worker.js". at api.js:2219:11
I fixed my issue it was a very simple missing "/" in worker source url. It seems it is unrelated to OP's issue:
pdfjsLib.GlobalWorkerOptions.workerSrc = "{{.Site.BaseURL}}" + 'js/pdf-js/build/pdf.worker.js';
chnged to this:
pdfjsLib.GlobalWorkerOptions.workerSrc = "{{.Site.BaseURL}}" + '/js/pdf-js/build/pdf.worker.js';
Hi I m seeing the same issue, it works on localhost, it does not work on live. I host my website in aws s3. I can download the pdf file, it just keeps loading without showing. In console I get the errors:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED pdf.worker.js:1 Uncaught (in promise) Error: Setting up fake worker failed: "Cannot load script at: https://<website-domain>js/pdf-js/build/pdf.worker.js". at api.js:2219:11
I fixed my issue it was a very simple missing "/" in worker source url. It seems it is unrelated to OP's issue:
pdfjsLib.GlobalWorkerOptions.workerSrc = "{{.Site.BaseURL}}" + 'js/pdf-js/build/pdf.worker.js';
chnged to this:
pdfjsLib.GlobalWorkerOptions.workerSrc = "{{.Site.BaseURL}}" + '/js/pdf-js/build/pdf.worker.js';
Same issue here and successfully fixed according to your method. thx
Not sure it can be of any help but I just had some similar issue.
From the README.md it is specified that pdf-js is now loaded from CDN, AFAIU that is not actually true since the embed-pdf file (on master branch at least) include it locally:
<script type="text/javascript" src= '/js/pdf-js/build/pdf.js'></script>
It shall be working also loading locally and I didn't try with Netlify but I was using github pages for deployment and if there is some extra path in your baseURL (e.g. if your baseURL is https://your-site/extra-path), loading the pdf-js file will fail with not found errors. This is because it will look on https://your-site/js/pdf-js/build/pdf.js that is incorrect because of the missing extra-path part of the URL. The correct URL would indeed be: https://your-site/extra-path/js/pdf-js/build/pdf.js. You can still fix this by properly using relURL or absURL in the script definition.
In my case I preferred relying on the CDN instead for pdf-js, interestingly enough indeed there is a not merged branch called install-submodule that has exactly the change you need to load pdf-js from CDN, so you can just change the submodules to track that branch instead of master and your problems will be solved.
You can see mine happily running on github pages: https://giacomocortesi.github.io/hugo-gc/resume/