<span id="qunw9"><kbd id="qunw9"><dfn id="qunw9"></dfn></kbd></span>
\n\n
\nContent\n<\/main>\n<\/body>\n<\/pre>\n\n\n

header.html
\n<\/p>\n

Welcome to the web site<\/header>\n<\/pre>\n\n\n

output
\n<\/p>\n


国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

\n
Welcome to the web site<\/header>\n
\nContent\n<\/main>\n<\/body>\n<\/pre>\n\n\n

When Compute entered the scene, the edge landscape changed in two main ways: programmability and modularity.<\/p>\n\n

Soon after our platform support for Rust had stabilized, we published a crate for Rust that implemented ESI, and added programmability. You could now configure, using code, how to build additional backend requests, and how to handle response fragments. You could even perform ESI processing on documents that don’t originate from the backend server. This programmability differentiated it from the ESI support we have in VCL, which was limited to the fixed set of features we offered.<\/p>\n\n

At the same time, this approach was highly modular, giving the programmer a choice to perform this ESI processing on a per-request basis, and the option to combine the processing with other modules that work with compatible data types, and apply them in any order and\/or logical condition specified.<\/p>\n

\n \n \n Next target: JavaScript\n<\/h2>\n\n

Similar to our Rust release, we wanted this JavaScript library to be programmable. Fastly’s JavaScript support has always embraced the Fetch API and its companion Streams API. One useful feature of the Streams API is the TransformStream interface, allowing for data to be “piped” through an object in order to apply a transformation—perfect for ESI. By implementing the ESI processor as an implementation of TransformStream, we were able to fit it right into a Fastly Compute Application written in JavaScript.<\/p>\n\n

Here's how you can stream through it:
\n<\/p>\n

\n\n
\nContent\n<\/main>\n<\/body>\n<\/pre>\n\n\n

The transformation, which we call the EsiTransformStream, is applied to the stream directly, alleviating memory and performance concerns. This means:<\/p>\n\n

    \n
  • There is no need to buffer the entire upstream response before applying the transformation.<\/li>\n
  • The transformer consumes the upstream response as quickly as it can, and processes ESI tags as they show up in the stream. As the transformer finishes processing each ESI tag, the results are released immediately downstream, so we are able to hold the minimal possible buffer. This allows the client to receive the first byte of the streamed result as it becomes ready, without having to wait for it to be processed in entirety.<\/li>\n<\/ul>\n\n

    In addition, this design is modular, making the EsiTransformStream just another tool you can use alongside other things. For example, you might have other transformations you want to apply to responses, like compression, and a response can be piped through any number of these transform streams, since it's a completely standard interface. If you wanted to, you could even conditionally enable ESI for just certain requests or responses, such as by request headers, paths, or response content type.<\/p>\n\n

    Here's how you instantiate EsiTransformStream:
    \n<\/p>\n

    Welcome to the web site<\/header>\n<\/pre>\n\n\n

    The constructor takes a URL and a Headers object, and optionally takes some options as a third parameter. As described earlier, the main functionality of ESI is to download additional templates, for inclusion into the resulting stream. Encountering an tag uses fetch as the underlying mechanism to retrieve a template, and the main purpose of these parameters is to configure those fetch calls:<\/p>\n\n

      \n
    • The URL is used to resolve relative paths in the src of tags.<\/li>\n
    • The Headers are used when making the additional requests to fetch the templates.<\/li>\n
    • The optional configuration object can be used to override the behavior of the fetch that is made, and to apply other custom behavior, such as how to process the fetched template, and custom error handling.<\/li>\n<\/ul>\n\n

      In the simplest case, you’ll use just the fetch value of the configuration object. If you don’t provide it, then it uses the global fetch function instead, but in Compute you’ll need it to specify a backend for the fetch to use when including a template (unless you’re using the dynamic backends feature). The example snippet above assigns the backend named origin_0 before calling the global fetch.<\/p>\n\n

      That’s it! With this simple setup you can have a backend serving ESI tags and a Compute application processing them. Here’s a full example that you can run:<\/p>\n\n\n

      \n \n fiddle.fastly.dev\n \n<\/div>\n

      \n \n \n Support for ESI features\n<\/h2>\n\n

      This implementation offers more ESI features than others we have made available in the past.<\/p>\n\n

      \n \n \n Error handling\n<\/h3>\n\n

      Sometimes, a file referenced by an tag may fail to fetch due to it not existing or causing a server error. It’s possible to ignore the error in these cases by adding the attribute onerror=\"continue\".
      \n<\/p>\n\n

      \n\n
      \nContent\n<\/main>\n<\/body>\n<\/pre>\n\n\n

      If \/templates\/header.html causes an error, the ESI processor silently ignores the error and replaces the entire tag with an empty string.<\/p>\n\n

      It’s also possible to use more structured error handling by employing an block, which looks like this:
      \n<\/p>\n

      Welcome to the web site<\/header>\n<\/pre>\n\n\n

      The ESI processor first executes the contents of . If an esi:include tag causes an error, then the ESI processor executes the contents of .<\/p>\n\n

      It’s important to note that the entire block is replaced by the entirety of the block if it succeeds or the if there is an error. In the above example, if \/templates\/header.html causes an error, then this also causes the text \"Main header\"<\/em> not to appear in the output; only the text \"Alternative header\"<\/em> is included. See the ESI language specification for more details.<\/p>\n

      \n \n \n Conditionals\n<\/h3>\n\n

      ESI also allows conditional execution, by performing runtime checks on variables. The following is an example of such a check:
      \n<\/p>\n

      \n
      Welcome to the web site<\/header>\n
      \nContent\n<\/main>\n<\/body>\n<\/pre>\n\n\n

      When the processor encounters an block, it runs through the blocks, checking the expressions set in their test attributes. The processor executes the first esi:when block where the expression evaluates to true. If none of the expressions evaluates to true, then it will optionally execute the esi:otherwise block if it’s provided. The entire block is replaced by the entirety of whichever or block that executes.<\/p>\n\n

      The processor makes available a limited set of variables, which are based primarily on request cookies. In the above example, an HTTP cookie by the name “group” is checked for its value. Our implementation is based on the ESI language specification; refer to it for more details.<\/p>\n

      \n \n \n List of supported tags and features\n<\/h3>\n\n

      This implementation supports the following tags of the ESI language specification.<\/p>\n\n

        \n
      • esi:include<\/li>\n
      • esi:comment<\/li>\n
      • esi:remove<\/li>\n
      • \nesi:try \/ esi:attempt \/ esi:except\n<\/li>\n
      • \nesi:choose \/ esi:when \/ esi:otherwise\n<\/li>\n
      • esi:vars<\/li>\n<\/ul>\n\n

        The tag is defined in the spec to be optional, and is not included in this implementation.<\/p>\n

        ESI Variables are supported in the attributes of ESI tags, and ESI Expressions are supported in the test attribute of . Additionally, the comment is supported.<\/p>\n

        \n \n \n Custom behavior means endless possibilities\n<\/h2>\n\n

        While the feature set is enough to get thrilled about, the truly exciting part of being programmable is that even more things are possible. Bringing in templates is the main use of ESI, but that’s by no means all that it can do. Here’s an example.<\/p>\n\n

        Consider you have a timestamp marked up in your document that you want represented as a relative date when it’s displayed, such as “2 days ago”. There are many ways of doing this, but to have the best performance and memory implications, it would be great to perform a find\/replace in streams. Programming this ESI library can actually be used as a good option for doing this.<\/p>\n\n

        We can define timestamps to be encoded in your backend document using a specially-crafted ESI tag in a format such as the following:
        \n<\/p>\n

        \n\n
        \nContent\n<\/main>\n<\/body>\n<\/pre>\n\n\n

        For example, this snippet can represent midnight on January 1, 2024, Pacific time:
        \n<\/p>\n

        Welcome to the web site<\/header>\n<\/pre>\n\n\n

        Now, set up the EsiTransformStream to serve a synthetic replacement document whenever it sees that URL pattern:
        \n<\/p>\n

        \n
        Welcome to the web site<\/header>\n
        \nContent\n<\/main>\n<\/body>\n<\/pre>\n\n\n

        Now, when the processor encounters the example snippet above, it will emit a result similar to the following (depending on how many days into the future you run it):
        \n<\/p>\n

        const transformedBody = resp.body.pipeThrough(esiTransformStream);\n\nreturn new Response(\n  transformedBody,\n  {\n    status: resp.status,\n    headers: resp.headers,\n  },\n);\n<\/pre>\n\n\n

        Because the backend document is cacheable by Fastly, future requests can benefit from a cache HIT, while the processing will continue to display the updated relative time.<\/p>\n\n

        For a live example of this, view the following fiddle:
        \n<\/p>\n

        \n \n fiddle.fastly.dev\n \n<\/div>\n\n\n\n

        \n \n \n Take it for a spin!\n<\/h2>\n\n

        @fastly\/esi is now available on npm, ready to be added to any JavaScript program. Use it at the edge in your Fastly Compute programs, of course, but in fact, it even works outside of Compute, so long as your environment supports the fetch API. The full source code is available on GitHub.<\/p>\n\n

        Get started by cloning either of the Fiddles above and testing them out with your own origins, even before you have created a Fastly account. When you’re ready to publish your service on our global network, you can sign up for a free trial of Compute and then get started right away with the ESI library on npm.<\/p>\n\n

        With Compute, the edge is programmable and modular – choose and combine the solutions that work best for you, or even build your own. We aren’t the only ones who can provide modules like this for Compute. Anyone can contribute to the ecosystem and take from it. And, as always, meet us at the Fastly community forum and let us know what you’ve been building!<\/p>\n\n\n \n\n \n "}

        Home Web Front-end JS Tutorial A modular Edge Side Includes component for JavaScript Compute

        A modular Edge Side Includes component for JavaScript Compute

        Dec 20, 2024 am 03:13 AM

        A modular Edge Side Includes component for JavaScript Compute

        In the summer of 2022, my teammate Kailan worked on a Rust crate for Fastly Compute, implementing a subset of the Edge Side Includes (ESI) templating language, and published a blog post about it. This article was significant not just because we released a useful library, but because it was a brilliant illustration of what Compute can bring us: a programmable edge with modular functionality. And now that JavaScript has been generally available on Compute for more than a year, it was time we had a similar solution for our JavaScript users. Fastly’s ESI library for JavaScript, now available on npm, allows you to add powerful ESI processing to your application.


        Programmability and Modularity

        For almost a decade, Fastly’s CDN has had support for Edge Side Includes (ESI), a templating language that works by interpreting special tags in your HTML source. It revolves around the tag , which instructs the edge server to fetch another document and inline it into the stream.

        index.html

        <body>
        <esi:include src="./header.html" />
        <main>
        Content
        </main>
        </body>
        

        header.html

        <header>Welcome to the web site</header>
        

        output

        
        <header>Welcome to the web site</header>
        
        Content

        When Compute entered the scene, the edge landscape changed in two main ways: programmability and modularity.

        Soon after our platform support for Rust had stabilized, we published a crate for Rust that implemented ESI, and added programmability. You could now configure, using code, how to build additional backend requests, and how to handle response fragments. You could even perform ESI processing on documents that don’t originate from the backend server. This programmability differentiated it from the ESI support we have in VCL, which was limited to the fixed set of features we offered.

        At the same time, this approach was highly modular, giving the programmer a choice to perform this ESI processing on a per-request basis, and the option to combine the processing with other modules that work with compatible data types, and apply them in any order and/or logical condition specified.

        Next target: JavaScript

        Similar to our Rust release, we wanted this JavaScript library to be programmable. Fastly’s JavaScript support has always embraced the Fetch API and its companion Streams API. One useful feature of the Streams API is the TransformStream interface, allowing for data to be “piped” through an object in order to apply a transformation—perfect for ESI. By implementing the ESI processor as an implementation of TransformStream, we were able to fit it right into a Fastly Compute Application written in JavaScript.

        Here's how you can stream through it:

        <body>
        <esi:include src="./header.html" />
        <main>
        Content
        </main>
        </body>
        

        The transformation, which we call the EsiTransformStream, is applied to the stream directly, alleviating memory and performance concerns. This means:

        • There is no need to buffer the entire upstream response before applying the transformation.
        • The transformer consumes the upstream response as quickly as it can, and processes ESI tags as they show up in the stream. As the transformer finishes processing each ESI tag, the results are released immediately downstream, so we are able to hold the minimal possible buffer. This allows the client to receive the first byte of the streamed result as it becomes ready, without having to wait for it to be processed in entirety.

        In addition, this design is modular, making the EsiTransformStream just another tool you can use alongside other things. For example, you might have other transformations you want to apply to responses, like compression, and a response can be piped through any number of these transform streams, since it's a completely standard interface. If you wanted to, you could even conditionally enable ESI for just certain requests or responses, such as by request headers, paths, or response content type.

        Here's how you instantiate EsiTransformStream:

        <header>Welcome to the web site</header>
        

        The constructor takes a URL and a Headers object, and optionally takes some options as a third parameter. As described earlier, the main functionality of ESI is to download additional templates, for inclusion into the resulting stream. Encountering an tag uses fetch as the underlying mechanism to retrieve a template, and the main purpose of these parameters is to configure those fetch calls:

        • The URL is used to resolve relative paths in the src of tags.
        • The Headers are used when making the additional requests to fetch the templates.
        • The optional configuration object can be used to override the behavior of the fetch that is made, and to apply other custom behavior, such as how to process the fetched template, and custom error handling.

        In the simplest case, you’ll use just the fetch value of the configuration object. If you don’t provide it, then it uses the global fetch function instead, but in Compute you’ll need it to specify a backend for the fetch to use when including a template (unless you’re using the dynamic backends feature). The example snippet above assigns the backend named origin_0 before calling the global fetch.

        That’s it! With this simple setup you can have a backend serving ESI tags and a Compute application processing them. Here’s a full example that you can run:

        fiddle.fastly.dev

        Support for ESI features

        This implementation offers more ESI features than others we have made available in the past.

        Error handling

        Sometimes, a file referenced by an tag may fail to fetch due to it not existing or causing a server error. It’s possible to ignore the error in these cases by adding the attribute onerror="continue".

        <body>
        <esi:include src="./header.html" />
        <main>
        Content
        </main>
        </body>
        

        If /templates/header.html causes an error, the ESI processor silently ignores the error and replaces the entire tag with an empty string.

        It’s also possible to use more structured error handling by employing an block, which looks like this:

        <header>Welcome to the web site</header>
        

        The ESI processor first executes the contents of . If an esi:include tag causes an error, then the ESI processor executes the contents of .

        It’s important to note that the entire block is replaced by the entirety of the block if it succeeds or the if there is an error. In the above example, if /templates/header.html causes an error, then this also causes the text "Main header" not to appear in the output; only the text "Alternative header" is included. See the ESI language specification for more details.

        Conditionals

        ESI also allows conditional execution, by performing runtime checks on variables. The following is an example of such a check:

        
        <header>Welcome to the web site</header>
        
        Content

        When the processor encounters an block, it runs through the blocks, checking the expressions set in their test attributes. The processor executes the first esi:when block where the expression evaluates to true. If none of the expressions evaluates to true, then it will optionally execute the esi:otherwise block if it’s provided. The entire block is replaced by the entirety of whichever or block that executes.

        The processor makes available a limited set of variables, which are based primarily on request cookies. In the above example, an HTTP cookie by the name “group” is checked for its value. Our implementation is based on the ESI language specification; refer to it for more details.

        List of supported tags and features

        This implementation supports the following tags of the ESI language specification.

        • esi:include
        • esi:comment
        • esi:remove
        • esi:try / esi:attempt / esi:except
        • esi:choose / esi:when / esi:otherwise
        • esi:vars

        The tag is defined in the spec to be optional, and is not included in this implementation.

        ESI Variables are supported in the attributes of ESI tags, and ESI Expressions are supported in the test attribute of . Additionally, the comment is supported.

        Custom behavior means endless possibilities

        While the feature set is enough to get thrilled about, the truly exciting part of being programmable is that even more things are possible. Bringing in templates is the main use of ESI, but that’s by no means all that it can do. Here’s an example.

        Consider you have a timestamp marked up in your document that you want represented as a relative date when it’s displayed, such as “2 days ago”. There are many ways of doing this, but to have the best performance and memory implications, it would be great to perform a find/replace in streams. Programming this ESI library can actually be used as a good option for doing this.

        We can define timestamps to be encoded in your backend document using a specially-crafted ESI tag in a format such as the following:

        <body>
        <esi:include src="./header.html" />
        <main>
        Content
        </main>
        </body>
        

        For example, this snippet can represent midnight on January 1, 2024, Pacific time:

        <header>Welcome to the web site</header>
        

        Now, set up the EsiTransformStream to serve a synthetic replacement document whenever it sees that URL pattern:

        
        <header>Welcome to the web site</header>
        
        Content

        Now, when the processor encounters the example snippet above, it will emit a result similar to the following (depending on how many days into the future you run it):

        const transformedBody = resp.body.pipeThrough(esiTransformStream);
        
        return new Response(
          transformedBody,
          {
            status: resp.status,
            headers: resp.headers,
          },
        );
        

        Because the backend document is cacheable by Fastly, future requests can benefit from a cache HIT, while the processing will continue to display the updated relative time.

        For a live example of this, view the following fiddle:

        fiddle.fastly.dev

        Take it for a spin!

        @fastly/esi is now available on npm, ready to be added to any JavaScript program. Use it at the edge in your Fastly Compute programs, of course, but in fact, it even works outside of Compute, so long as your environment supports the fetch API. The full source code is available on GitHub.

        Get started by cloning either of the Fiddles above and testing them out with your own origins, even before you have created a Fastly account. When you’re ready to publish your service on our global network, you can sign up for a free trial of Compute and then get started right away with the ESI library on npm.

        With Compute, the edge is programmable and modular – choose and combine the solutions that work best for you, or even build your own. We aren’t the only ones who can provide modules like this for Compute. Anyone can contribute to the ecosystem and take from it. And, as always, meet us at the Fastly community forum and let us know what you’ve been building!

        The above is the detailed content of A modular Edge Side Includes component for JavaScript Compute. For more information, please follow other related articles on the PHP Chinese website!

        Statement of this Website
        The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

        Hot AI Tools

        Undress AI Tool

        Undress AI Tool

        Undress images for free

        Undresser.AI Undress

        Undresser.AI Undress

        AI-powered app for creating realistic nude photos

        AI Clothes Remover

        AI Clothes Remover

        Online AI tool for removing clothes from photos.

        Clothoff.io

        Clothoff.io

        AI clothes remover

        Video Face Swap

        Video Face Swap

        Swap faces in any video effortlessly with our completely free AI face swap tool!

        Hot Tools

        Notepad++7.3.1

        Notepad++7.3.1

        Easy-to-use and free code editor

        SublimeText3 Chinese version

        SublimeText3 Chinese version

        Chinese version, very easy to use

        Zend Studio 13.0.1

        Zend Studio 13.0.1

        Powerful PHP integrated development environment

        Dreamweaver CS6

        Dreamweaver CS6

        Visual web development tools

        SublimeText3 Mac version

        SublimeText3 Mac version

        God-level code editing software (SublimeText3)

        Java vs. JavaScript: Clearing Up the Confusion Java vs. JavaScript: Clearing Up the Confusion Jun 20, 2025 am 12:27 AM

        Java and JavaScript are different programming languages, each suitable for different application scenarios. Java is used for large enterprise and mobile application development, while JavaScript is mainly used for web page development.

        Javascript Comments: short explanation Javascript Comments: short explanation Jun 19, 2025 am 12:40 AM

        JavaScriptcommentsareessentialformaintaining,reading,andguidingcodeexecution.1)Single-linecommentsareusedforquickexplanations.2)Multi-linecommentsexplaincomplexlogicorprovidedetaileddocumentation.3)Inlinecommentsclarifyspecificpartsofcode.Bestpractic

        How to work with dates and times in js? How to work with dates and times in js? Jul 01, 2025 am 01:27 AM

        The following points should be noted when processing dates and time in JavaScript: 1. There are many ways to create Date objects. It is recommended to use ISO format strings to ensure compatibility; 2. Get and set time information can be obtained and set methods, and note that the month starts from 0; 3. Manually formatting dates requires strings, and third-party libraries can also be used; 4. It is recommended to use libraries that support time zones, such as Luxon. Mastering these key points can effectively avoid common mistakes.

        JavaScript vs. Java: A Comprehensive Comparison for Developers JavaScript vs. Java: A Comprehensive Comparison for Developers Jun 20, 2025 am 12:21 AM

        JavaScriptispreferredforwebdevelopment,whileJavaisbetterforlarge-scalebackendsystemsandAndroidapps.1)JavaScriptexcelsincreatinginteractivewebexperienceswithitsdynamicnatureandDOMmanipulation.2)Javaoffersstrongtypingandobject-orientedfeatures,idealfor

        Why should you place  tags at the bottom of the ? Why should you place tags at the bottom of the ? Jul 02, 2025 am 01:22 AM

        PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl

        JavaScript: Exploring Data Types for Efficient Coding JavaScript: Exploring Data Types for Efficient Coding Jun 20, 2025 am 12:46 AM

        JavaScripthassevenfundamentaldatatypes:number,string,boolean,undefined,null,object,andsymbol.1)Numbersuseadouble-precisionformat,usefulforwidevaluerangesbutbecautiouswithfloating-pointarithmetic.2)Stringsareimmutable,useefficientconcatenationmethodsf

        What is event bubbling and capturing in the DOM? What is event bubbling and capturing in the DOM? Jul 02, 2025 am 01:19 AM

        Event capture and bubble are two stages of event propagation in DOM. Capture is from the top layer to the target element, and bubble is from the target element to the top layer. 1. Event capture is implemented by setting the useCapture parameter of addEventListener to true; 2. Event bubble is the default behavior, useCapture is set to false or omitted; 3. Event propagation can be used to prevent event propagation; 4. Event bubbling supports event delegation to improve dynamic content processing efficiency; 5. Capture can be used to intercept events in advance, such as logging or error processing. Understanding these two phases helps to accurately control the timing and how JavaScript responds to user operations.

        What's the Difference Between Java and JavaScript? What's the Difference Between Java and JavaScript? Jun 17, 2025 am 09:17 AM

        Java and JavaScript are different programming languages. 1.Java is a statically typed and compiled language, suitable for enterprise applications and large systems. 2. JavaScript is a dynamic type and interpreted language, mainly used for web interaction and front-end development.

        See all articles