3

We have several page layouts that are calling a javascript file and we are trying to improve our page speeds and we figured we only need to call this js file if the user is logged in. Otherwise for anonymous users, we don't need to load it.

Is there any way to do this?

1 Answer 1

3

Yes, inside the .aspx files for the layout, use the Security Trimmed Control:

https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.webcontrols.spsecuritytrimmedcontrol.aspx

Specifically you'd probably do something like this:

<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" AuthenticationRestrictions="AuthenticatedUsersOnly" runat="server">
    <script src="JavaScriptForAuthenticatedUsersOnly.js"></script>
</SharePoint:SPSecurityTrimmedControl>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.