目录

Customizing Page Request Responses

The Web component supports customizing request responses after the app intercepts a page request. You can use the onInterceptRequest() API to implement custom resource request responses. The custom request capability can be used in scenarios such as custom web page responses and custom file resource responses.

When a resource loading request is initiated on a web page, the application layer will receive the request. The application layer then constructs a local resource response and sends it to the web kernel. On receiving the response, the web kernel parses the response and loads page resources accordingly.

In the following example, the Web component intercepts the page request https://www.example.com/test.html, and a response resource is constructed in the app-side code to implement a custom page response scenario.

Generate a CodeCache object for a custom JavaScript request response: If the resource of a custom request response is a JavaScript script, you can add the ResponseDataID field to the response header. After the web kernel reads this field, it generates a CodeCache for the JS resource to accelerate JS execution. If ResponseData is updated, this field must be updated accordingly. If the ResponseDataID field is not added, no CodeCache is generated by default.

In the following example, the Web component intercepts the page request https://www.example.com/test.js; a response resource is constructed in the app-side code, and the ResponseDataID field is added to the response header to enable CodeCache generation.