How to remove sf_appPath javascript variable from a Sitefinity MVC Page

by Vesselin Vassilev


Last Updated On Jul 10, 2018


If you have the Personalization module enabled, then you'll notice that a global javascript variable called sf_appPath is injected to all pages of your site. It usually looks like this:

<script type="text/javascript">var sf_appPath='/';</script>

This Sitefinity KB article suggests that you should not try to remove this from your MVC Feather pages.
What if you have a valid reason to do so? 
Here is one such reason - I want to have my own custom MVC page template for AMP pages. If I create the template and have the personalization module enabled, even though my AMP pages are not personalized - that javascript variable still gets injected to the code, rendering the pages AMP-invalid. 
The Sitefinity's Mobile Formats module, which is the Sitefinity's implementation of AMP pages, uses its own page template, but there are two things I don't like about it:
- the template is placed in a non-standard location - MVC / Views / AMP / 
- You cannot create your own pages based on that page template

For those reasons, I needed to have my own page template for AMP pages, have the Personalization module activated (but not used by the amp pages) and have the sf_appPath variable removed from the page source.

Here is how to do it (public gist)



Copyright © Sitefinity Development