sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Loading JS files in <head> tag using SPFx. Similar to SiteCustomActions !

Open dmahendranme opened this issue 8 years ago • 4 comments

Category

  • [x] Question
  • [ ] Typo
  • [ ] Bug
  • [ ] Additional article idea

Question

This is the exact scenario we are in. @PopWarner have asked right questions but no acceptable responses :( Any update on this?

We want to load our JS before the tag renders. Any solution on that? Tried ApplicationCustomizer but it is not we want because it is just inserting the reference on head tag after body tag renders.

Do you have any solution on new SPFx v1.6?

Use Case: Some analytics scripts wants to be rendered before the body tag.

Thanks for your contribution! Sharing is caring.

dmahendranme avatar Sep 08 '18 15:09 dmahendranme

No, at this moment we do not have a way to inject pure script onto the page above the head element (assuming that is what you mean by "before the tag renders").

What analytics are you looking to do?

patmill avatar Sep 10 '18 22:09 patmill

@patmill I think there is an issue with GitHub. I mentioned that "before the body tag renders" but it is displaying as "before the tag renders". Sorry for the confusion.

On the documentation, it is mentioned that;

The logic for your Application Customizer is contained in the onInit method, which is called when the client-side extension is first activated on the page. This event occurs after this.context and this.properties are assigned. As with web parts, onInit()returns a promise that you can use to perform asynchronous operations.

I assume that this code is executed after the body content is loaded (like document.ready). We wanted to have a solution like SiteCustomActions on classic SharePoint.

The analytics we are using is Riverbed's AppInternals. One of their instruction is to have the code on head tag (i.e., we should not add it to the head tag after the dom elements are loaded).

Here is the snapshot of the existing setup we use on classic SharePoint. It loads as part of the page load. image

Implemented using PnP image

dmahendranme avatar Sep 11 '18 16:09 dmahendranme

As this is a new feature request, we would ask you to vote for following - https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/suggestions/19536304-extensions-application-customizer-loading-js-fi.

VesaJuvonen avatar Oct 04 '18 17:10 VesaJuvonen

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar Jan 26 '20 18:01 msft-github-bot