Help Needed: Serving PDF.js Express UI and CSS Fil...
# questions
j
Help Needed: Serving PDF.js Express UI and CSS Files from JavaScript Directory in Grails 6 Hi everyone, I’m working on integrating PDF.js Express into my Grails 6 application, but I’ve run into some issues related to serving static assets. Specifically, I want to serve UI and CSS files from within the
javascripts
directory (to keep the library structure intact), but I’m getting 404 errors. My Setup: • Grails Version: 6.x • *Asset Directory Structure:*grails-app/assets/javascripts/ext/pdf-express/lib/ • ├── core/ • ├── ui/ • │ ├── assets/ • │ ├── chunks/ • │ ├── i18n/ • │ ├── configorigin.txt • │ ├── index.html • │ ├── style.css • │ ├── webviewer-ui.min.js • └── webviewer.min.js • References in GSP Files: • html • link rel=“stylesheet” href=“${resource(dir: ‘javascripts/ext/pdf-express/lib/ui’, file: ‘style.css’)}” /script src=“${resource(dir: ‘javascripts/ext/pdf-express/lib/ui’, file: ‘webviewer-ui.min.js’)}“/scriptscript src=“${resource(dir: ‘javascripts/ext/pdf-express/lib’, file: ‘webviewer.min.js’)}“/script The Problem: When I load my page, I get 404 errors for the CSS and JS files under the
ui
directory: •
GET <https://mydomain/static/javascripts/ext/pdf-express/lib/ui/style.css> 404
GET <https://mydomain/static/javascripts/ext/pdf-express/lib/ui/webviewer-ui.min.js> 404
GET <https://mydomain/static/javascripts/ext/pdf-express/lib/webviewer.min.js> 404
What I’ve Tried: • I haven’t yet configured
application.yml
specifically for this but suspect that the Asset Pipeline might not be set up to serve files from the
javascripts
folder when those files aren’t JS files. • I’ve been advised to include these directories explicitly in the
application.yml
, but I’d like to confirm the best practice before proceeding. application.yml grails:
Copy code
assets:
  includes:
    # Include all files for PDF.express view PDF library so css and images can be served from javascript folder
    - 'javascripts/ext/pdf-express/lib/**/*'
What I’m Asking: • Has anyone successfully served CSS and UI files from within the
javascripts
directory?
Is there a recommended way to configure the Grails Asset Pipeline to handle this setup without moving files? Any advice or configuration examples would be greatly appreciated! Thanks in advance for your help!
j
asset-pipeline takes resources in assets/javascripts and puts them directly into /assets/. It does the same for assets/images and assets/stylesheets. So you can reference as •
<link rel="stylesheet" href="${resource(dir: 'ext/pdf-express/lib/ui', file: 'style.css')}" />
• <script src=“${resource(dir: ‘ext/pdf-express/lib/ui’, file: ‘webviewer-ui.min.js’)}“></script> • <script src=“${resource(dir: ‘ext/pdf-express/lib’, file: ‘webviewer.min.js’)}“></script> or you can double up the directory assets/javascripts/javascripts and the resources will end up in assets/javascripts
j
Thanks for your Answer James @James Fredley, very much appreciated! I got caught up in an other topic, that I have to solve first. Will get back to hopefully the solution of this later.