Forum Discussion

Mohemmad Kalva's avatar
Mohemmad Kalva
Copper Contributor
Dec 18, 2017
Solved

How to disable public CDN for particular site collection?

I have implemented on master page in which I had referenced the css and js file using relative URLs to the site.

 

After that, I enabled the public CDN for Office 365 to deploy the SPFx components. 

 

When I visited the site where I had implemented the custom master page and layouts, I found that the relative URLs are now pointing to the CDN and the site stopped working.

 

How do I disable this behavior? i.e. I want to deploy the assets of SPFx to the public cdn but the existing implementation of the master page should not get affected if given the relative URLs for the files.

 

Please suggest me the steps.

  • Robert Schouten's avatar
    Robert Schouten
    Dec 19, 2017

    You're welcome!

    On your Office 365 CDN remove the default origin for masterpage:

     

    Remove-SPOTenantCdnOrigin -CdnType Public -OriginUrl */MASTERPAGE

     

    This will remove the default CDN origin with wildcard, which will be for every site collection in your tenant (remove others to if necessary like */STYLE LIBRARY). 

    Add a new origin with a OriginUrl pointing to the site collection and master page gallery location Like:

     

    Add-SPOTenantCdnOrigin -CdnType public -OriginUrl sites/yoursitecollection/_catalogs/masterpage

    This way you have configured only your site collection masterpage catalog to be a CDN enabled library. You could also point it to a folder in your library to scope it more specific.

     

    Hope this helps!

  • Maybe you could add your SPFx assets into a subfolder in the Masterpage gallery and Add that folder as a CDN origin, using Add-SPOTenantCdnOrigin. Remove the generally added Cdn origin to the Masterpage gallery. This way only the assets in the subfolder are CDN enabled. As mentioned use Remove-SPOTenantCdnOrigin to remove the on pointing to the Masterpage gallery. 

     

    Next to this you could also create a Cdn origin pointing to a specific site, instead of using a wildcard and doing this for all sites. Use a originUrl in this format:

     

    -OriginUrl sites/site1/siteassets
    • Mohemmad Kalva's avatar
      Mohemmad Kalva
      Copper Contributor

      Thanks for replying..!!

       

      The site collection where my custom master page has been applied and the site where I am deploying the SPFx web parts are different.

       

      So, I want the solution where I can run the SPFx web part from Office 365 CDN and the custom master page does not affected in another site collection.

      • Robert Schouten's avatar
        Robert Schouten
        MVP

        You're welcome!

        On your Office 365 CDN remove the default origin for masterpage:

         

        Remove-SPOTenantCdnOrigin -CdnType Public -OriginUrl */MASTERPAGE

         

        This will remove the default CDN origin with wildcard, which will be for every site collection in your tenant (remove others to if necessary like */STYLE LIBRARY). 

        Add a new origin with a OriginUrl pointing to the site collection and master page gallery location Like:

         

        Add-SPOTenantCdnOrigin -CdnType public -OriginUrl sites/yoursitecollection/_catalogs/masterpage

        This way you have configured only your site collection masterpage catalog to be a CDN enabled library. You could also point it to a folder in your library to scope it more specific.

         

        Hope this helps!

  • Master pages gallery is added by default as a CDN endpoint when public CDN is enabled. To remove it from public CDN, use the Remove-SPOTenantCdnOrigin PowerShell command.

    This change will be applied to all site collections as it's a tenant setting. I don't think you can set distinct settings per site collection.

Resources