How to remove sf_appPath javascript variable from a Sitefinity MVC Page
See how to remove the sf_appPath javascript variable from your Sitefinity MVC pages while having the Personalization module on.
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:
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)
<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)