Git Product home page Git Product logo

Comments (5)

twifkak avatar twifkak commented on April 28, 2024

For the cloudflare_worker, we might be able to use HTMLRewriter in order to avoid growing the bundle size. It is supposed to be efficient, based on its underlying library LOL HTML. (Not sure; just an idea.)

from sxg-rs.

twifkak avatar twifkak commented on April 28, 2024

I'm not going to finish this before my vacation, so I'm saving state:

#68 is worse than I'd thought. The segfault happens even on HtmlRewriter::new(). So I think we have a few options (rough order of preference):

  1. Duplicate the HTML code. In cloudflare_worker, use the JS HtmlRewriter API. In fastly_compute, use the Rust HtmlRewriter. Is the duplication reasonably small/manageable?
  2. Fix #68. Are the install instructions still reasonable?
  3. See if we can use another HTML parser like html5ever or (via FFI) LazyHTML. Does this address the segfault? Is the bundle size & performance OK?
  4. Some hacky regex for parsing the link tags, and validate the hrefs & params look OK (e.g. don't break the browser's Link header parser). Leave a comment in the README that things that look like tags inside script, noscript, template, or maybe foreign contexts like svg/html might cause a spurious prefetch.

As for what the HTML parser does, it converts <link rel=preload as=foo> tags into Link header directives. It should also add the parameters crossorigin, media, imagesrcset, and imagesizes if specified.

We have a choice, we can either:

  1. Mandate the document is UTF-8 and verify it has a <meta> tag that declares as such, and doesn't have a UTF-16 BOM.
  2. Try and detect the character encoding the way that Chromium does (as the only SXG browser engine right now, and the likely portrait of future browser behavior per whatwg/html#6962).

Link dump:

Possible test set dump:

Advice dump:

  • Remember rel can contain multiple (whitespace-separated).
  • BOM sniffing overrides <meta> so we must check either way.

from sxg-rs.

twifkak avatar twifkak commented on April 28, 2024

Remaining task is to implement on fastly_compute.

from sxg-rs.

twifkak avatar twifkak commented on April 28, 2024

Oh, also remaining is to process additional attributes besides {rel,href,as}. Here's link's supported attributes.

For certain, we should support imagesrcset and imagesizes, as I know these are supported by SXG subresources. I'm not sure about crossorigin, and referrerpolicy; we should see what Chromium (and/or the spec) does. I'm pretty sure media is not supported because a document frame isn't constructed by a prefetch event. The others don't seem relevant.

from sxg-rs.

twifkak avatar twifkak commented on April 28, 2024

Implementing for fastly_compute should be easy now that process_html.rs exists.

from sxg-rs.

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.