Forum Discussion
Javascript insert to HTML
Hello all,
Is it possible to insert a small piece of Javascript into HTML when traffic passes through the LTM into a certain virtual server? So one of our 3rd party vendor we use for monitoring solutions has a javascript that can be use to insert into HTML in order to compute performance measurements. Is it possilbe to create an iRule to go about this or is there a better way of doing this on the F5 itself? Any help is appreciated. Here is the piece of javascript they want inserted into HTML:
10 Replies
- Kevin_Stewart
Employee
There's several ways to do this, but I prefer a STREAM profile for its simplicity, flexibility, and speed. To make it work, apply a generic STREAM profile to your virtual server and this iRule:
when HTTP_REQUEST { Disable the stream filter for all requests STREAM::disable LTM does not decompress response content, so if the server has compression enabled and it cannot be disabled on the server, we can prevent the server from sending a compressed response by removing the compression offerings from the client HTTP::header remove "Accept-Encoding" } when HTTP_RESPONSE { Check if response type is text if { [HTTP::header value Content-Type] contains "text" } { Define the stream replacement STREAM::expression {@@@} Enable the stream filter for this response only STREAM::enable } }
- Kevin_Stewart
Employee
The editor messed up the iRule. Trying again:when HTTP_REQUEST { Disable the stream filter for all requests STREAM::disable LTM does not decompress response content, so if the server has compression enabled and it cannot be disabled on the server, we can prevent the server from sending a compressed response by removing the compression offerings from the client HTTP::header remove "Accept-Encoding" } when HTTP_RESPONSE { Check if response type is text if { [HTTP::header value Content-Type] contains "text" } { Define the stream replacement STREAM::expression {@@@} Enable the stream filter for this response only STREAM::enable } }
- TNY_122436
Nimbostratus
Kevin, I greatly appreciate your help. I'm going to implement this and see how it goes. I will let you know. - TNY_122436
Nimbostratus
Kevin, I just noticed that in my original thread, some of my contents of the javascript was missing. Here is the javascript code again. Let me know if there should be changes to the stream expression base on what I missed originally:
- Kevin_Stewart
Employee
What I did in the STREAM expression was to remove the JavaScript code from the function and simply embed it at the end of the document within script tags. So your STREAM expression basically looks like this:{@@@}
- TNY_122436
Nimbostratus
Arr...sorry, here is the full quote: - Kevin_Stewart
Employee
This STREAM replacement abandons the JavaScript function at the beginning of the document and adds a block of JavaScript at the end of the document (without the function)....
- TNY_122436
Nimbostratus
Ok. So is this what I should put this in the new Stream:: expression?:Define the stream replacement STREAM::expression {@@@}
- Kevin_Stewart
Employee
Almost:Define the stream replacement STREAM::expression {@@@}
- TNY_122436
Nimbostratus
Thanks Kevin! I'll do some testing and let you know how it goes.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com