Forum Discussion

fzaborowski_311's avatar
fzaborowski_311
Icon for Nimbostratus rankNimbostratus
Apr 05, 2010

iRule 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.

 

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    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
  • 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's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    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