https://discord.cloudflare.com logo
Join Discord
Powered by
# functions
  • g

    gerred

    11/20/2021, 10:11 PM
    what got me asking about that was how pages functions works today under the hood.
  • g

    gerred

    11/20/2021, 10:12 PM
    is that a generalizable model, I suppose. 🙂
  • g

    gerred

    11/20/2021, 10:12 PM
    I feel like I'm generating out some big isolates locally, but maybe not.
  • w

    William | Chaos Management

    11/20/2021, 10:12 PM
    assuming I have a pages function at
    functions/api/lookup.js
    I could request it from
    /api/lookup
    , right?
  • g

    Greg Brimble | Cloudflare Pages

    11/20/2021, 10:12 PM
    Oh, no. Normal Workers are very much their own thing, and they aren't combined in any funky ways whatsoever.
  • g

    gerred

    11/20/2021, 10:12 PM
    👍
  • i

    itsmatteomanf

    11/20/2021, 10:12 PM
    Technically it's the opposite, the more you combine, the less chances the Worker is cold. But cold starts aren't really that big of an issue on paid plans, if at all.
  • g

    gerred

    11/20/2021, 10:12 PM
    OH that's a fair point. and yeah, but as we're looking at moving over, we're pulling in some large WASM bits - hopefully eventually we can drag those out from R2, but we're early in this process.
  • w

    wonkrattle

    11/20/2021, 10:12 PM
    Can you write a normal function that adds content to an existing static page or is that purely the domain of an HTMLrewriter
  • w

    wonkrattle

    11/20/2021, 10:13 PM
    Because like this weather endpoint is great, but what if I want to put it into a page
  • i

    itsmatteomanf

    11/20/2021, 10:13 PM
    The optimization is, the bigger it gets, the more time it takes to parse and execute (not much, it's still V8 and it's very fast), but a 1kB worker vs. a 1MB worker has different parse times.
  • g

    Greg Brimble | Cloudflare Pages

    11/20/2021, 10:13 PM
    It's what HTMLRewriter was built for, but you can definitely do it yourself if you prefer:
    Copy code
    js
    response = await fetch()
    text = await response.text()
    text += '<h1>Hello</h1>'
    return new Response(text)
  • i

    itsmatteomanf

    11/20/2021, 10:13 PM
    -> HTMLRewriter.
  • g

    Greg Brimble | Cloudflare Pages

    11/20/2021, 10:14 PM
    HTMLRewriter will give you better performance.
  • i

    itsmatteomanf

    11/20/2021, 10:14 PM
    Also, note to everyone. The employee here is @User, I'm not 🙂
  • w

    wonkrattle

    11/20/2021, 10:14 PM
    That makes sense, so do I basically just create a tag with a name and some filler content that gets replaced basically.
  • g

    Greg Brimble | Cloudflare Pages

    11/20/2021, 10:15 PM
    I'd be happy to chat about how best to use HTMLRewriter if you've got a specific example of problem you're trying to solve 🙂
  • w

    wonkrattle

    11/20/2021, 10:15 PM
    (i’m going off the example here https://developers.cloudflare.com/workers/tutorials/localize-a-website#overview)
  • g

    gerred

    11/20/2021, 10:15 PM
    totally, I'm trying not to use the embedding of v8 we've written at my startup unless it's on our clients' hardware (so basically, move our backend over to workers if we can), i've been deep in this "hell" (not really hell, but it's intricate obviously)
  • m

    Mark Hood

    11/20/2021, 10:15 PM
    I wasn’t aware that was needed… back to the docs I go! Thanks for the advice.
  • g

    gerred

    11/20/2021, 10:15 PM
    the clarification there suggests though for us I should have a separate API set of workers from what we would do with pages for the auth/etc parts of the service.
  • w

    wonkrattle

    11/20/2021, 10:16 PM
    So the content that is currently in the weather.JS file, I would like to put it onto a specific page of my website (index.html): https://www.chrisfnicholson.com
  • g

    gerred

    11/20/2021, 10:16 PM
    @User form submitted (among many others), thank you for answering on your weekend.
  • g

    Greg Brimble | Cloudflare Pages

    11/20/2021, 10:17 PM
    If your site has static assets, and you're wanting to deploy everything together, then full-stack Pages is what I'd recommend going with. If it makes sense for your application, stick with the
    functions
    dir handlers.
    _worker.js
    is a primarily an escape-hatch for either people with existing Workers, or framework authors.
  • w

    wonkrattle

    11/20/2021, 10:17 PM
    So that at the bottom there it would just say the temperature in Denver is 51 degrees.
  • g

    gerred

    11/20/2021, 10:17 PM
    @User that makes sense, thank you.
  • i

    itsmatteomanf

    11/20/2021, 10:17 PM
    The docs for
    wrangler@beta
    aren't great, but it's
    beta
    after all. Look at @User's stream at https://twitch.tv/gregbrimble
  • g

    Greg Brimble | Cloudflare Pages

    11/20/2021, 10:17 PM
    If you need stability though, Workers have been around since (I think) 2017, so are a lot more mature than the beta Pages functions 🙂
  • g

    Greg Brimble | Cloudflare Pages

    11/20/2021, 10:18 PM
    npx wrangler pages dev --help
    should give you all the options you have available 🙂
  • g

    gerred

    11/20/2021, 10:18 PM
    oh yeah, that I'm familiar with! just for the first time this has all come together in a way I think we can fully put something together and drop a crap ton of tools. nice work.
1...789...392Latest