Coder Social home page Coder Social logo

Comments (8)

snshn avatar snshn commented on August 19, 2024

Hey there! That's interesting. I don't think the network panel errors is a huge problem, as long as the assets load. Do they appear to be missing/broken in the saved HTML file, when the browser renders the page?

from monolith.

Explosion-Scratch avatar Explosion-Scratch commented on August 19, 2024

@snshn Yes, they don't load. This is then reflected in the Network panel - The CSS file in question was several megabytes and so the data URL didn't work. The page then looked weird because it didn't have the CSS

from monolith.

snshn avatar snshn commented on August 19, 2024

Uh-oh, that's a real boo-boo. Thank you for letting me know. I've done some research prior on minimizing image size, I believe that could help. What browser was it in, if I may ask?

from monolith.

Explosion-Scratch avatar Explosion-Scratch commented on August 19, 2024

@snshn Modern chrome 😅 (120 I think). You can embed the string in JavaScript then create a blob URL though if it's too long, e.g:
img.src = new URL.createObjectURL(new Blob([data here])), then the blob url would be very short, that does mess things up though with the initial load.

For CSS and JS you could turn <link rel="stylesheet" href="https://example.com/style.css"> to <style>[embedded css here]</style> and likewise for script[src] to <script> (be careful with attributes like defer though)

from monolith.

snshn avatar snshn commented on August 19, 2024

Ideally JS should be unobtrusive, many people disable it by default (e.g. NoScript extension), and modifying the original document way too much could cause other problems (aside from blowing up the code base of Monolith), but you're suggesting very good solutions, thank you. I'll look into MHTML more, it could be a good format for solving these types of issues, but I agree that it's a big problem, I'm honestly a bit shocked there's a limit on the length in the browser, I assumed it's something like file size — as long as the machine has enough memory, it should work.

from monolith.

Explosion-Scratch avatar Explosion-Scratch commented on August 19, 2024

@snshn Your project seems a lot like SingleFile, you could see how they do it

from monolith.

snshn avatar snshn commented on August 19, 2024

If it's been solved in SingleFile, it's likely done the way you've described it — using JS to build blobs and unwrapping assets, embedding them into the HTML. I rather stay away from relying on JS, but if there's no better alternative, that approach is better than nothing. It still looks like a browser issue more than the tool's issue, as there's no length limit in the spec, that's just something browsers impose. I will eventually make Monolith reduce file size of embedded assets by not using base64 when not necessary, that's upcoming in future versions. I'll see how MHTML behaves and what could be done with large files (e.g. splitting one .js file into multiple consequently-included .js files, doing the same with .css assets). There's always a way.

from monolith.

Explosion-Scratch avatar Explosion-Scratch commented on August 19, 2024

@snshn For all styles and scripts you can simply inline them using script and style tags instead of link/script[src]. This should solve the issue most of the time, for images you could:

  1. compress them (convert to avif/webp, etc)
  2. just inline them anyways and hope it works out (browser have different limits)
  3. pick 1 or 2 then use JS on page load providing at least an ok solution for people without JS.

from monolith.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.