[Epub] Recommendation on handling relative assets/css #99
-
ContextI am trying out and learning how to apply Approach
ProblemMy current problem is that I do not know how to handle CSS/assets defined as relative links in the epub archive. For example, this epub has images and CSS files: And the various HTML files reference them relatively: RequirementsThere is no intention to statically serve these files. The above problem should easily work if the files are served in the same folder and the relative links 'just work', but I want to do this without physically storing the files (e.g. a user should be able to upload an Potential Solution
I think this could work in theory, but there's potential duplication of CSS and assets for each HTML page (most likely CSS duplication). Questions
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Note: I roughly browsed through the source code of Would like to know and get recommendations from the community on how this could be solved/organized in the |
Beta Was this translation helpful? Give feedback.
-
Either way could work, The pros and cons aren't necessarily unified related.
If you want everything to load at once, inline/encode the content.
It depends on if duplication matters in your use-case. |
Beta Was this translation helpful? Give feedback.
-
Update: using the quick approach above, I was able to render epub pages in a a controlled manner with a simple implementation. https://unified-doc.netlify.app/examples/epub (source code link in example). Keeping track of assets by ID and only generating them as inlined styles and data URLs when a specific page is rendered seems to work well. There are some obvious holes and edge cases not handled, but I'll continue to flesh it out over time in the future. One main challenge is not knowing how to replace links within Ebook pages. I'm not sure how to handle this given the approach I've taken. The only way I can think of is to turn links into click handlers that allows the appilcation sitting above the rendering code to decide which page to navigate to. It's likely not possible to simply use semantic links in the simple approach I've taken. |
Beta Was this translation helpful? Give feedback.
Either way could work, The pros and cons aren't necessarily unified related.
If you want everything to load at once, inline/encode the content.
If you way to lazy-load or deliver different versions the content, externalize it.
It depends on if duplication matters in your use-case.
If you all inline content, there is a possibility of duplication, that may be fine, it reduces the number of network calls to get a page to one.
If you externalize the content you can prevent duplication, but extern…