docs/en/docs/rules/jsPrepend.md
Inserts the specified content before the existing response body. (This only works for responses with content-type containing javascript and a status code containing a body (e.g., 200/500).)
⚠️ Note: Requests without a body, such as 204 and 304 responses, are not affected.
pattern jsPrepend://value [filters...]
| Parameters | Description | Detailed Documentation |
|---|---|---|
| pattern | An expression to match against the request URL | Match Pattern Documentation |
| value | Text or binary content. Supports the following types: | |
| • Directory/File Path | ||
| • Remote URL | ||
| • Inline/Embedded/Values Content | Operation Instruction Documentation | |
| filters | Optional filters. Supports matching: | |
| • Request URL/Method/Headers/Content | ||
| • Response Status Code/Headers | Filter Documentation |
www.example.com/path1 jsPrepend://(Hello) file://(-test-)
www.example.com/path2 jsPrepend://(Hello) file://(-test-) resType://js
www.example.com/path3 jsPrepend://(Hello) file://(-test-) resType://css
https://www.example.com/path1/to. The response content becomes
<!DOCTYPE html>
<script>Hello</script>-test-
https://www.example.com/path2/to. The response content becomes Hello-test-https://www.example.com/path3/to becomes -test-``` body.txt
Hello world.
```
www.example.com/path1 jsPrepend://{body.txt} file://(-test-)
www.example.com/path2 jsPrepend://{body.txt} file://(-test-) resType://js
www.example.com/path3 jsPrepend://{body.txt} file://(-test-) resType://css
https://www.example.com/path1/to, the response content becomes
<!DOCTYPE html>
<script>Hello world.</script> -test-
https://www.example.com/path2/to, the response content becomes Hello world.-test-https://www.example.com/path3/to. The response content becomes -test-.www.example.com/path1 jsPrepend:///User/xxx/test.js
www.example.com/path2 jsPrepend://https://www.xxx.com/xxx/params.js
# Editing a temporary file
www.example.com/path3 jsPrepend://temp/blank.js
<script> Tag Attributes for Injected ScriptsScripts injected into HTML pages via jsPrepend are automatically wrapped in <script> tags by Whistle. To set additional attributes for these tags—such as nomodule, module, defer, async, or crossorigin—you can use the lineProps parameter for configuration.
www.example.com/path1 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://nomodule
www.example.com/path2 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://module
www.example.com/path3 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://defer
www.example.com/path4 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://async
www.example.com/path5 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://crossorigin
| Attribute | Purpose | Configuration Example |
|---|---|---|
nomodule | Executes in traditional browsers; this script will run in browsers that do not support ES modules. | lineProps://nomodule |
module | Declares the script as an ES module, enabling modular imports. | lineProps://module |
defer | Loads asynchronously and executes after the document has been parsed. | lineProps://defer |
async | Loads asynchronously and executes immediately after download. | lineProps://async |
crossorigin | Enables Cross-Origin Resource Sharing (CORS) mode. | lineProps://crossorigin |
Prepend To Body): resPrependPrepend HTML To Body, response type must be text/html): htmlPrependPrepend CSS To Body, response type must be text/html or text/css): cssPrependPrepend JS To Body, response type must be text/html, text/css, or application/javascript): jsPrependReplace Body): resBodyReplace Body, response type must be text/html): htmlBodyReplace Body, response type must be text/html or text/css): cssBodyReplace Body, response type must be text/html, text/css, or application/javascript): jsBodyAppend To Body): resAppendAppend HTML To Body, response type must be text/html): htmlAppendAppend CSS To Body, response type must be text/html or text/css): cssAppendAppend JS To Body, response type must be text/html, text/css, or application/javascript): jsAppendModify Body Text): resReplaceModify Form/JSON): resMergeDelete Form/JSON): delete://resBody.xxx