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

Styelsheet URL breaks when moving up in the directory "../" #95

Closed
julienetie opened this issue Jul 18, 2015 · 9 comments
Closed

Styelsheet URL breaks when moving up in the directory "../" #95

julienetie opened this issue Jul 18, 2015 · 9 comments

Comments

@julienetie
Copy link

This:

     background: url('../folder/image.jpg');

becomes:

     background: url('folder/image.jpg');

It's not always convenient when taking src from a different directory (unless I'm doing something wrong) The same applies for multiple traversing. I found this but I'm not sure if the change will break anything:

lib/inline-styles.js

function rebaseRelativePaths(basePath, cssPath, cssStr) {
..//
                    for (var k = 0; k < pathDiff; k++) {
                        newPath = newPath.replace('../', '');
                    }
//..
}

Maybe remove the back tracking of dir could be better as an option.

@bezoerb
Copy link
Collaborator

bezoerb commented Jul 18, 2015

@julienetie could you provide some more information about your setup?

@julienetie
Copy link
Author

Sure:

So this is the css src

    background: #222 url('../funny-how.jpg') repeat-y;

which critical outputs into the html as:

    background: #222 url('funny-how.jpg') repeat-y;

gulpfile.js

gulp.task('build-404-critical-css', ['build-404-css'], function() {
    return critical.generateInline({
        base: './',
        src: './src/html/404.html',
        css: ['./style/404.min.css'],
        htmlTarget: './404/index.php',
        exclude: true,
        width: 1366,
        height: 4000,
        minify: true
    });
});

@bezoerb
Copy link
Collaborator

bezoerb commented Jul 19, 2015

@julienetie i've made some tests but i couldn't reproduce your issue.
The background-image in the critical css always resolves to url('/funny-how.jpg')

Which version of critical are using?

@bezoerb
Copy link
Collaborator

bezoerb commented Jul 19, 2015

You also could use the stream method when using with gulp.

@julienetie
Copy link
Author

Thanks @bezoerb, I'll give it a try.

@bezoerb
Copy link
Collaborator

bezoerb commented Aug 6, 2015

@julienetie any updates on this one?

@SerzN1
Copy link

SerzN1 commented Nov 13, 2015

You must use option
pathPrefix: '/' + yourPath
Your code will be immediately on the page.

bezoerb added a commit that referenced this issue Jan 28, 2016
We now can campute the path prefix for asset references based on the location of the html file.
This allows us to keep relative asset urls in stylesheets relative. Issues #57 and #95
@bezoerb bezoerb mentioned this issue Jan 28, 2016
@bezoerb
Copy link
Collaborator

bezoerb commented Feb 4, 2016

We've made some progress on this topic @julienetie. The asset paths inside the critical css should now stay relative in case they were relative the first place. Could you check if your issue is fixed in the vinyl branch?

npm install --save-dev git+https://github.com/addyosmani/critical.git#vinyl

/cc @SerzN1

addyosmani pushed a commit that referenced this issue Oct 17, 2016
* add testcase for #119

* use vinyl

* Keep relative images relative

We now can campute the path prefix for asset references based on the location of the html file.
This allows us to keep relative asset urls in stylesheets relative. Issues #57 and #95

* consider absolute stylesheet refs

* Guess source path for piped html

try to guess source path of the file by checking relative links inside the html source
show warning to the user when no relative links are available

* tests for auto pathPrefix

* travis tweaks

some weird issue requires a second npm install to add all deps
without this module minimist required by gulp-util is missing

* eslint fixes

* minor changes

* doc blocks

* compatibility to vinyl < v0.5.3

* Check vinyl

* Check vinyl

* remove unused setMaxListeners(0)

* guess path to html source

also consider script sources

* fixed jsdoc

* add 'folder' option

* updated jsdoc

* text change

* WiP

* fixed tests

* run all tests

* some text changes

* fixed tests

* force re-run appveyor after penthouse fix

* fixed tests

* fixed last test
@bezoerb
Copy link
Collaborator

bezoerb commented Jul 1, 2017

Closing this due to lack of feedback. Feel free to reopen if you still got problems on this one.

@bezoerb bezoerb closed this as completed Jul 1, 2017
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

3 participants