We recently created a view that used teasers for nodes, which didn't have the maps showing (excluded from the Display settings). However, the Javascript srcs to Google and Bing were still being added. That's fine, but when we have a view with ten nodes, and then each layer for Google and Bing, we were having about 70 includes for the script. Obviously... this slowed down page performance. So, here's a little patch that'll help things out.

The patch creates a few static variables, and only includes the scripts on the first time around.

(Patch to be included in reply so I can use the issue number in it)

Files: 
CommentFileSizeAuthor
#1 openlayers-809208.patch5.18 KBmikesir87

Comments

mikesir87’s picture

StatusFileSize
new5.18 KB

Patch is attached.

tmcw’s picture

Good catch, and the patch looks solid. I'll test briefly and commit.

zzolo’s picture

@mikesir87 good catch. It is because we have to utilize drupal_set_html_head() which does not do any sort of checking or overwriting. Does it make sense to provide a help function for this? All you would need is a function that takes an ID with the JS to include.

mikesir87’s picture

@zzolo sure! that could definitely work. would you like me to make one up, or will you handle it?

tmcw’s picture

Not terribly opposed to the idea of encapsulating it, but I think that it might be making the layer type prototype more complex for an incomplete win - I'd imagine that there are also cases in which commercial layers are including, say, two javascript files, or a css file, in the same pattern but with different code. This would be the perfect place for a ruby-style block input, but alas this is PHP, and I'm not sure that this is the best idea.

tmcw’s picture

Status:Active» Fixed

Committed in its current form: http://drupal.org/cvs?commit=372508

We can open a ticket for refactoring if needed? Anyway, I wanted to get this in so that a refactor can be tested against it, and we don't have lots of uncommitted patches.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.