Optimizing Office 365 – Content Delivery Network

Content Delivery Network (CDN) 

A CDN is comprised of a system of distributed servers (network) that delivers commonly used static pages across the information systems such as JavaScript files (jQuery framework), CSS branding files. These files are stored on specific servers based on the geographic locations of the user, the origin of the webpage and the content delivery server.

CDN’s help keep Office 365 fast and reliable for end users by caching cache static assets closer to the browsers requesting them to speed up downloads and reduce perceived end user latency.

Note: The Office 365 CDN is not the same as the Azure CDN.

Office 365 CDN 

Office 365 includes a native CDN feature that is included as part of the SharePoint Online subscription. Office 365 CDN uses the HTTP/2 protocol for improved compression and download speeds.

The feature provides support for both Private and Public CDN.

Private: Private access to static assets in the Office 365 CDN is granted by tokens generated by SharePoint Online.
  1. Users who already have permission to access to the folder or library designated by the origin will automatically be granted tokens.
  2. SharePoint Online does not support item-level permissions for the CDN.

Figure 1: Logical Illustration of Private CDN (Courtesy: Microsoft)

#Adds specified Origin Url of the SPO Tenant to the CDN 
Add-SPOTenantCdnOrigin -CdnType Private -OriginUrl */CLIENTSIDEASSETS
Add-SPOTenantCdnOrigin -CdnType Private -OriginUrl */MASTERPAGE
Add-SPOTenantCdnOrigin -CdnType Private -OriginUrl '*/STYLE LIBRARY'

Script 3: PowerShell cmdlet for enabling private CDN on the specified Origin Url 

Public: Assets exposed in a public origin are accessible by everyone anonymously. Since the access to the content is anonymous, this type of CDN is used to
  1. cache non-sensitive generic content such as JavaScript files, scripts, icons and images.
  2. download generic resource assets like the Office 365 client applications from a public origin.

Figure 2: Logical Illustration of Public CDN (Courtesy: Microsoft)

#Adds specified Origin Url of the SPO Tenant to the CDN 
Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl */CLIENTSIDEASSETS
Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl */MASTERPAGE
Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl '*/STYLE LIBRARY'

Script 4: PowerShell cmdlet for enabling public CDN on the specified Origin Url 

Planning  for Office 365 CDN

The PowerShell cmdlets to enable CDN on the tenant is provided below

#Needs to be an admin site 
Connect-SPOService -Url <Tenant SharePoint Admin URL> 

#Enable Office 365 Private CDN in the tenant 
Set-SPOTenantCdnEnabled -CdnType Private -Enable $true

#Enable Office 365 Public CDN in the tenant 
Set-SPOTenantCdnEnabled -CdnType Public -Enable $true

#Enable both Office 365 Public and Private CDN in the tenant 
Set-SPOTenantCdnEnabled -CdnType Both -Enable $true

#If either Azure CDN or a custom third party CDN is used 
Set-SPOTenantCdnEnabled -CdnType Both -Enable $true -NoDefaultOrigins

 Script 1: PowerShell cmdlet for enabling private CDN on a tenant 

Note: The system takes about 30 minutes to synchronize the configuration across the data-center. During this time status will be “Configuration pending” which is expected as the SharePoint Online tenant connects to the CDN service. 

Office 365 CDN provides IT administrators a high level of flexibility in specifying which content is hosted in the CDN by specifying origin URL. The origin URL can point to either a SharePoint library or folder. The assets stored in the library or folder will be  synced to the CDN hosts. In addition, Admins have the flexibility to specify the file types to be included in CDN. In addition, Admins have the flexibility to specify the file types to be included in CDN.

#Set the file types to be included in the CDN 
Set-SPOTenantCdnPolicy -CdnType Public -PolicyType IncludeFileExtensions -PolicyValue "CSS, GIF,ICO,JPEG,JPG,JS"

#Sets the CDN to a Public type except for the site classifications included in the exclusion list
Set-SPOTenantCdnPolicy -CdnType Public -PolicyType ExcludeRestrictedSiteClassifications -PolicyValue "Confidential,Restricted"

Script 2: PowerShell cmdlet for setting granular configuration settings 

Note: It’s not possible to modify an existing CDN origin. Instead, an existing CDN origin can be modified by first removing the previously defined CDN origin using the Remove-SPOTenantCdnOrigin cmdlet and add a new one using the Add-SPOTenantCdnOrigin cmdlet.