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

With autogenerate_stylesheet=true, many redundant styles are generated #294

Open
msvanvertloo opened this issue Jan 9, 2014 · 1 comment

Comments

@msvanvertloo
Copy link

Every time a widget is added dynamically, the stylesheet is reconstructed and added to the DOM (rather than replacing what's already there or building only the additional styles needed). After this happens a few times, the browser starts to have noticeable performance issues when dragging tiles around. If the redundant styles are not generated, the dragging behavior doesn't experience any performance penalty (using Chrome Version 31.0.1650.63 m).

@joaquindiez
Copy link

I did a small modification in the gridster code to fix that, I added an id to the css node generated, then I check if the node was previously generated to avoid added again

fn.add_style_tag = function(css) { var d = document; var current_css = $('#_gridster_auto_css'); if (current_css === 'undefined' || current_css.length == 0){ var tag = d.createElement('style'); d.getElementsByTagName('head')[0].appendChild(tag); tag.setAttribute('type', 'text/css'); tag.setAttribute('id', '_gridster_auto_css'); if (tag.styleSheet) { tag.styleSheet.cssText = css; }else{ tag.appendChild(document.createTextNode(css)); } this.$style_tags = this.$style_tags.add(tag); } return this; }; And in the generate_stylesheet method

I deleted this code lines

// don't duplicate stylesheets for the same configuration
var serialized_opts = $.param(opts);
if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) {
return false;
}

and add instead

$('#_gridster_auto_css').remove();

to be sure I was to generate a unique css.

dasmall added a commit to dasmall/gridster.js that referenced this issue Apr 10, 2014
vieron pushed a commit that referenced this issue Jun 16, 2014
dsmorse pushed a commit to dsmorse/gridster.js that referenced this issue Apr 8, 2015
* dasmall/gridster.js.git/master:
  Removing previously added style tags before adding new one. Hopefully fixes ducksboard#211 and ducksboard#294.
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