← Back to scottjehl/Respond

How to Deploy & Use scottjehl/Respond

Respond.js Deployment and Usage Guide

Prerequisites

  • Runtime Environment: Respond.js is a JavaScript library that runs in web browsers, specifically targeting Internet Explorer 6-8 and other browsers without native CSS3 Media Query support.
  • Web Server: Required for proper functionality, as the script uses AJAX to fetch CSS files. File URLs (file://) may not work due to security restrictions.
  • CSS Files: Your project should use CSS3 Media Queries with min-width and max-width for responsive design.

Installation

  1. Download the Library:

    • Download the latest version from the GitHub releases page or use the CDN version.
    • Include the script in your HTML after all CSS files.
  2. Manual Installation:

    <script src="path/to/respond.min.js"></script>
    
  3. CDN Installation (recommended for production):

    <script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
    

Configuration

  • CDN/X-Domain Setup: If your CSS files are hosted on a CDN or subdomain, configure a local proxy to serve CSS files to older IE browsers. This is necessary because Respond.js uses AJAX to fetch CSS files.
  • Caching: Ensure your CSS files are properly cached to prevent unnecessary re-requests when Respond.js fetches them via AJAX.

Build & Run

Development

  1. Include Respond.js in Your HTML:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Responsive Design with Respond.js</title>
        <link rel="stylesheet" href="styles.css">
        <script src="respond.min.js"></script>
    </head>
    <body>
        <!-- Your content here -->
    </body>
    </html>
    
  2. CSS with Media Queries:

    /* Mobile-first approach */
    body {
        font-size: 16px;
    }
    
    @media screen and (min-width: 480px) {
        body {
            font-size: 18px;
        }
    }
    
    @media screen and (min-width: 768px) {
        body {
            font-size: 20px;
        }
    }
    

Production

  • Use the minified version (respond.min.js) to reduce file size.
  • Ensure proper caching headers are set on your server for CSS files.

Deployment

  • Web Servers: Deploy to any web server (Apache, Nginx, IIS, etc.) that can serve your HTML, CSS, and JavaScript files.
  • CDN: For optimal performance, host your CSS files on a CDN and configure a local proxy for older IE browsers as mentioned in the configuration section.
  • Static Site Hosts: Platforms like Netlify, Vercel, or GitHub Pages work well for static sites using Respond.js.

Troubleshooting

Common Issues and Solutions

  1. Media Queries Not Working in IE:

    • Ensure Respond.js is loaded after all CSS files.
    • Check that CSS files are accessible via HTTP/HTTPS, not file:// URLs.
  2. CSS Files Not Loading:

    • Verify that CSS files return a 200 status code (not redirected).
    • Ensure CSS files are not encoded in UTF-8 with BOM, which can cause issues in IE7/8.
  3. Performance Issues:

    • Use the minified version of Respond.js.
    • Configure proper caching for CSS files to avoid unnecessary AJAX requests.
  4. Font-Face Rules Hanging IE7/8:

    • Place @font-face rules outside of media queries to prevent hanging.
  5. More Than 32 Stylesheets:

    • IE throws an error if more than 32 stylesheets are referenced. Concatenate your CSS files.
  6. Nested Media Queries:

    • Respond.js does not support nested media queries. Flatten your CSS structure.
  7. Sass/SCSS Source Maps:

    • @media -sass-debug-info will break Respond.js. Remove or disable source maps in production.
  8. IE9 in Frames:

    • If using IE9 within frames, media queries in external CSS files may fail. Apply the fix from this commit.

Debugging

  • Use browser developer tools to check if Respond.js is loaded and if there are any console errors.
  • Verify that CSS files are being fetched correctly by checking the Network tab in developer tools.

By following this guide, you should be able to successfully implement Respond.js in your project to enable responsive design in older browsers that don't support CSS3 Media Queries.