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

    Better James

    02/27/2023, 4:25 PM
    Because vercel decided to in their build output. As I'm thinking about it, I recall seeing some regex in next-on-pages for this specifically, so i'll go yoink that for now
  • b

    Better James

    02/27/2023, 4:26 PM
    But thanks for that clarification, I didn't realise they all end up compiled together at the end of the day.
  • b

    Better James

    02/27/2023, 4:28 PM
    Does that mean the workers size limit applies to all function route files combined together, or is that size limit per function file?
  • k

    kian

    02/27/2023, 4:28 PM
    When they're combined together, yep
  • k

    kian

    02/27/2023, 4:29 PM
    When you're using the
    /functions
    folder, they're all bundled up together into a single worker.js - the 'Advanced Mode' is where you just write your own
    _worker.js
    and that's effectively what framework adaptors do
  • s

    Skye

    02/27/2023, 4:29 PM
    It's worth noting that the size limit is after gzipping
  • k

    kian

    02/27/2023, 4:30 PM
    You can also normally do `--minify`/`minify = true` with Workers but I don't think the Pages commands expose that
  • b

    Better James

    02/27/2023, 4:31 PM
    Oh man
  • k

    kian

    02/27/2023, 4:31 PM
  • b

    Better James

    02/27/2023, 4:32 PM
    I was going to try and be all clever and have everything done with a separate function file for each route in nextjs like vercel's uses, instead of one big _worker.js file that next-on-pages does
  • b

    Better James

    02/27/2023, 4:32 PM
    I feel like that is something that should be clearer in the docs, because I didn't realise that at all when I was skimming them earlier
  • h

    HardAtWork

    02/27/2023, 4:49 PM
    I believe Vercel does the same thing, you just don't see it because it happens on-platform.
  • h

    HardAtWork

    02/27/2023, 4:49 PM
    At least for Edge Functions
  • b

    Better James

    02/27/2023, 4:50 PM
    I guess so
  • h

    HardAtWork

    02/27/2023, 4:50 PM
    Because afaik, Vercel is also limited by the 1-5 MB Worker size limit, just like everyone else.
  • b

    Better James

    02/27/2023, 4:51 PM
    Just strikes me as odd that they'd output all the fluff like that if they're not going to consume it like that
  • b

    Better James

    02/27/2023, 4:51 PM
    and by fluff i mean all the stuff that duplicated across each file
  • l

    Larry

    02/27/2023, 7:15 PM
    @Better James , I had a similar reaction when I learned it all got bundled up together. However, I don't really think about it from day to day because it's hidden from me and I get this nice file system router functionality. That said, I'm not sure what you mean by "stuff that [gets] duplicated". The boilerplate is as little as one line per file in my experience and rarely more than a few lines. When it is, I break it out into a helper file that gets imported into all Functions that need it.
  • s

    Skye

    02/27/2023, 7:18 PM
    In the case of next on pages, there's a lot of duplicate code per route at the moment is the point that was being made afaik
  • b

    Better James

    02/27/2023, 7:18 PM
    I was looking specifically at the vercel output when building nextjs, and each function route for each page that vercel builds includes all the code needed for said page. You can in theory run each page completely separately of any other with its built function. So, when I was referring to duplicated code, it's stuff like the manifests, core react stuff, core nextjs stuff, core build stuff that is in each file so that each can run completely independently of another
  • s

    Skye

    02/27/2023, 7:18 PM
    Such as https://github.com/cloudflare/next-on-pages/issues/47
  • b

    Better James

    02/27/2023, 7:19 PM
    If I was writing my own functions it would be a completely different case, but in this instance I was looking at what vercel builds to see if I could leverage it in a way different to next-on-pages. Unfortunately, that misunderstanding means I can't
  • p

    Pause

    02/27/2023, 7:20 PM
    is it possible to fetch an image and then insert it with HTMLRewriter? as a blob, I suppose
  • k

    kian

    02/27/2023, 7:22 PM
    I guess it'd be some variation of
  • p

    Pause

    02/27/2023, 7:29 PM
    hmmm... I'm assuming createObjectURL doesn't work with workers
  • p

    Pause

    02/27/2023, 7:29 PM
    is that meant to be an address to a local file?
  • p

    Pause

    02/27/2023, 7:29 PM
    not quite sure how to make this work
  • k

    kian

    02/27/2023, 7:31 PM
    It indeed does not exist in Workers
  • k

    kian

    02/27/2023, 7:31 PM
    Welp
  • p

    Pause

    02/27/2023, 7:35 PM
    oh maybe base64 encoding the image
1...353354355...392Latest