Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External resources do not appear to honour priority order #146

Open
ProNotion opened this issue Jul 12, 2018 · 6 comments
Open

External resources do not appear to honour priority order #146

ProNotion opened this issue Jul 12, 2018 · 6 comments

Comments

@ProNotion
Copy link

ProNotion commented Jul 12, 2018

In an Umbraco site I have a master view that adds common scripts like so:

Html.RequiresJs("~/scripts/common.js", 1);

In a child view I then might register additional scripts like so:

Html.RequiresJs("https://maps.googleapis.com/maps/api/js?key=xxx", 0)
	.RequiresJs("~/scripts/plugins/infobox.js", 8)
	.RequiresJs("/scripts/map.js", 9);

The problem I have is that common.js has references to the Google Maps APi which fail because the API is not loaded in until after the script itself because the final rendering order is as follows:

<script src="/DependencyHandler.axd?s=L3NjcmlwdHMvYWxsLm1pbi5qczs&amp;t=Javascript&amp;cdv=2005391810"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=xxx"></script>

WHen in fact I would expect, and need, it to be the other way around:

<script src="https://maps.googleapis.com/maps/api/js?key=???"></script>
<script src="/DependencyHandler.axd?s=L3NjcmlwdHMvYWxsLm1pbi5qczs&amp;t=Javascript&amp;cdv=2005391810"></script>

Is this by design?

@Shazwazza
Copy link
Owner

No it should do as you expect, CDF will stagger any external dependencies so will always render them separately (unless you've configured it to fetch external resources locally ... not recommended).

Can you replicate with a simple setup? seems odd since this is pretty basic functionality of cdf.

@ProNotion
Copy link
Author

Thanks for the quick response Shannon, I will see if I can replicate it in a clean build. FWIW this is a Umbraco v7.7.0 site currently.

@Shazwazza
Copy link
Owner

Just need to find out if this is the order that the views are rendering and where you are rendering your scripts out, etc... or if it's just a strange bug that's never been discovered somehow :)

My advise though is to avoid registering dependencies inside partials, etc... I realize that was one of the original ideas behind this lib but it's not exactly best practices since depending on how you are rendering views there's various ways to make this fail (i.e. caching views, child actions, other odd ordering). I'd advise creating named bundles if you can which cdf supports too.

@ProNotion
Copy link
Author

Aha, named bundles you say. I've not come across those so will look into that.

@Shazwazza
Copy link
Owner

Sorry not a ton of docs but you can find info here https://github.com/Shazwazza/ClientDependency/wiki#pre-defined-bundles

@Shazwazza
Copy link
Owner

Then you need to require your bundle like RequiresJsBundle and then render as per normal, ideally i'd have this done #1 ... but not a lot of time and probably wont invest more effort apart from bug fixing to CDF since Smidge supercedes it (but haven't got that working nicely with .NET Framework just yet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants