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

CSS from external domains shouldn't be fetched #8

Open
wuservices opened this issue Mar 22, 2012 · 0 comments
Open

CSS from external domains shouldn't be fetched #8

wuservices opened this issue Mar 22, 2012 · 0 comments

Comments

@wuservices
Copy link

I made a small tweak to cssSandpaper which you might want to integrate. I noticed that it tries to AJAX in stylesheets but most of the time that isn't possible due to same origin policy. Ignoring CORS, I think the best is to just exclude cross domain files.

Of course that poses an issue for files on CDN but I think that should be up to the implementor to figure out. In my case I'm doing everything programatically anyways so maybe I'd even want to disable all the AJAX requests to boost performance but that's a separate issue.

    function getStyleSheet(node){
        var sheetCssText;
        switch (node.nodeName.toLowerCase()) {
            case 'style':
                sheetCssText = StringHelpers.uncommentHTML(node.innerHTML); //does not work with inline styles because IE doesn't allow you to get the text content of a STYLE element
                break;
            case 'link':
                // Don't fetch stylesheets cross domain since cross domain errors will appear
                var domainMatch = /\/\/(.*?)\//.exec(node.href);
                if (domainMatch !== null && domainMatch[1] !== location.hostname) {
                  return '';
                }

                var xhr = XMLHelpers.getXMLHttpRequest(node.href, null, "GET", null, false);
                sheetCssText = xhr.responseText;

                break;
        }

        sheetCssText = sheetCssText.replace(reMultiLineComment, '').replace(reAtRule, '');

        return sheetCssText;
    }
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

1 participant