Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
Like Tree3Likes
  • 1 Post By TheGAME1264
  • 2 Post By Ronald Roe

Thread: Is it not recommended to use @import?

  1. #1
    Junior Member
    Join Date
    Jan 2016
    Posts
    8
    Member #
    52916

    Is it not recommended to use @import?

    Hello there,
    I am working on a website and I use @import to import css files based on the width of the viewport, but I just read an article about how using @import can cause performance and Javascript problems.
    What do you think about this?

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Never heard of any Javascript problems myself because I don't really use the @import statement, but whenever you @import another file, it creates an additional HTTP request for the server to handle. That can slow down your site.
    Christo95 likes this.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Quote Originally Posted by TheGAME1264 View Post
    Never heard of any Javascript problems myself because I don't really use the @import statement, but whenever you @import another file, it creates an additional HTTP request for the server to handle. That can slow down your site.
    Actually, it depends on how much CSS we're talking. >2Kb in CSS, which isn't a whole lot, it's actually faster to part the files out.

    As far as JS is concerned, the only real issue would be if the JS is loading before the CSS and depends on certain CSS values. Even then, if you're firing the JS properly, such as using onload events, that would be a non-issue.
    TheGAME1264 and Christo95 like this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  5. #4
    Junior Member
    Join Date
    Jan 2016
    Posts
    8
    Member #
    52916
    Quote Originally Posted by Ronald Roe View Post
    Actually, it depends on how much CSS we're talking. >2Kb in CSS, which isn't a whole lot, it's actually faster to part the files out.

    As far as JS is concerned, the only real issue would be if the JS is loading before the CSS and depends on certain CSS values. Even then, if you're firing the JS properly, such as using onload events, that would be a non-issue.

    So I am just gonna have to make sure the script fires after CSS has been fully loaded, do you think onload event is the best way to do this? or is there a better way?

  6. #5
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Quote Originally Posted by Christo95 View Post
    So I am just gonna have to make sure the script fires after CSS has been fully loaded, do you think onload event is the best way to do this? or is there a better way?
    It's the only surefire way to ensure all of the assets have loaded before you run your script. There are other ways, but they aren't entirely reliable, such as putting the script at the bottom of the page. You can put it there, and it'll probably fire after the CSS loads, but if your CSS isn't loaded and parsed yet, the script will fire too soon.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Tags for this Thread

All times are GMT -6. The time now is 04:47 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com