Forum Discussion
fzaborowski_311
Nimbostratus
Apr 05, 2010iRule Javascript call?
Hi,
Quick question (I haven't seen this done/documented here):
I wish to call a .js file for users accessing certain pages. The script simply tags their page for us to monitor their performance. Is this possible from within an iRule?
Something like:
when HTTP_REQUEST {
if { [HTTP::uri] contains "/FooPage/" } {
CALL JS SCRIPT FROM WEB SERVER FIRST (prebody), AND ALLOW SESSION TO CONTINUE.
}
}
Thanks for any suggestions or examples you may be aware of.
4 Replies
- hoolio
Cirrostratus
Hi,
Can you clarify what you're trying to achieve? Do you want to inject javascript in the response content? Or do you want to actually force LTM to make a request to a Javascript file and send that as the response to any request containing /FooPage/ in the URI?
Thanks, Aaron - fzaborowski_311
Nimbostratus
Hi Aaron,
Actually-you are correct-injecting it into response is what I wanted and I believe I have found how to do that based upon syntax examples and a Google Analytics example found here.
I guess my question now is (as I am, obviously, not overly familiar with iRule usage):
I could not properly nest the HTTP_RESPONSE_DATA code within a HTTP_REQUEST looking for specific uri info, does the iRules function such that if it misses the REQUEST filter, that the next WHEN statement is bypassed as well as it is part of the same iRule or will other traffic be affected by that 2nd statement injecting the js?
Sorry if this is lame-I haven't had need previously to use these in such a manner. I do appreciate any info.
I will likely run this with simple logging as the actions to see what turns up.
Thanks again! - hoolio
Cirrostratus
The URI isn't saved for response events. So you could check the URI in HTTP_REQUEST and then set a variable to 1 to track whether to inject the javascript in the response:when HTTP_REQUEST { Check if some URI property is true if {[string tolower [HTTP::path]] contains "/foopage/"}{ Track that we'll inject the js in the response set inject_js 1 } else { Track that we won't inject the js in the response set inject_js 0 } } when HTTP_RESPONSE { Check whether we're injecting the js in the response payload if {$inject_js==1}{ Do it... } }
Also note that it would probably be more efficient to use a stream profile to insert the javascript. See this post for a related example:
http://devcentral.f5.com/Default.aspx?tabid=53&aff=5&aft=1144860&afv=topic&afpgj=1
Aaron - fzaborowski_311
Nimbostratus
Thanks again Aaron-for taking the time to respond. It is very much appreciated.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
