Tip #699: Don’t go back on context

Tima and PunishmentThis one is for javascript lovers. If you work with HTML web resources, you know that you need to include ClientGlobalContext.js.aspx to get CRM context in your script.

If everything is working correctly but you receive JS error “GetClientContext is not defined” when using back button in Chrome browser, add dummy query parameter to the script url:

<script 
  src="../../ClientGlobalContext.js.aspx?type=script"
  type="text/javascript">
</script>

This is because ClientGlobalContext.js.aspx has some narcissistic tendencies: after it’s been loaded, it loads itself again but not as script but as xhr type – and that one unexpectedly overwrites the cached script.

If you’re yearning for more details, read the nail-biting story of discovery and enlightment at Daryl “New MVP on the block” LaBar blog.

Share on FacebookTweet about this on TwitterShare on Google+

Leave a Reply

Your email address will not be published. Required fields are marked *