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

Javescript compression in .htaccess #41

Closed
sheixt opened this issue Sep 3, 2014 · 2 comments
Closed

Javescript compression in .htaccess #41

sheixt opened this issue Sep 3, 2014 · 2 comments

Comments

@sheixt
Copy link

sheixt commented Sep 3, 2014

I've used the 'compression' section of the .htacess file & noticed (thanks to gzipwtf.com) that the Javascript compression doesn't seem to work. It would seem there is a missing reference to text/javascript.

Here is the updated code snippet that I used, hope it helps:

<IfModule mod_deflate.c>

    # Force compression for mangled headers.
    # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping
    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ 

HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
        </IfModule>
    </IfModule>

    # Compress all output labeled with one of the following MIME-types
    # (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
    #  and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
    #  as `AddOutputFilterByType` is still in the core directives).
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE application/atom+xml \
                                      application/javascript \
                                      application/json \
                                      application/rss+xml \
                                      application/vnd.ms-fontobject \
                                      application/x-font-ttf \
                                      application/x-web-app-manifest+json \
                                      application/xhtml+xml \
                                      application/xml \
                                      font/opentype \
                                      image/svg+xml \
                                      image/x-icon \
                                      text/css \
                                      text/javascript \
                                      text/html \
                                      text/plain \
                                      text/x-component \
                                      text/xml
    </IfModule>

</IfModule>

[This has been migrated from https://github.com/h5bp/html5-boilerplate/issues/1592]

@alrra
Copy link
Member

alrra commented Sep 3, 2014

@sheixt Like I said before, can you try to include also the "media types" section (or at least this line) and tell me if that takes care of it. Also, make sure you have mod_mime enabled. Thanks!


Note to self: As quite a few people only use parts of the .htaccess file, it may be useful to also include text/javascript in the configs.

alrra added a commit that referenced this issue Sep 3, 2014
By default the configurations from this repository ensure that
`.js` files are served with the `application/javascript` media
type, compressed, and with far future expires headers. However,
not all users¹ use all the configurations provided by this
project, or, in some cases, the headers are overwritten from the
level "beneath" Apache (e.g.: from `php`).

For most of these cases we can't do anything about it.
Nonetheless, there is one, quite common case (the media type is
set to `text/javascript`) where we can help.

Since the `text/javascript` media type is used² quite often, this
commit makes Apache serve anything labeled with this media type,
compressed and with far future expires headers.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

¹ #27
  #41

² Even the Google CND serves `.js` files with the `text/javascript`
  media type (e.g.: http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js)
@alrra
Copy link
Member

alrra commented Sep 3, 2014

Note to self: As quite a few people only use parts of the .htaccess file, it may be useful to also include text/javascript in the configs.

Done in db69327.

@alrra alrra closed this as completed Sep 3, 2014
alrra added a commit that referenced this issue Oct 17, 2014
By default the configurations from this repository ensure that
`.js` files are served with the `application/javascript` media
type, compressed, and with far future expires headers. However,
not all users¹ use all the configurations provided by this
project, or in some cases, the headers are overwritten from the
level "beneath" Apache (e.g.: from `php`).

Looking at the results from the HTTP Archive² from 01.09.2014:

  +---+--------------------+--------------------------+
  |   | number of requests |        media type        |
  +---+--------------------+--------------------------+
  | 1 |            7406888 | image/jpeg               |
  | 2 |            4547461 | image/png                |
  | 3 |            4003685 | image/gif                |
  | 4 |            3087744 | text/html                |
* | 5 |            2112777 | text/javascript          |
  | 6 |            1798370 | text/css                 |
* | 7 |            1740983 | application/x-javascript |
* | 8 |            1394717 | application/javascript   |
  |   |                ... |                      ... |
  +---+--------------------+--------------------------+

it's clear that the `application/javascript` media type is used
less often than both `text/javascript` and `application/x-javascript`.

Because of the above, the changes from this commit will ensure that
Apache will serve anything labeled with the `application/x-javascript`,
compressed and with far future expires headers (a previous commit³ did
the same for the files labeled as `text/javascript`).

- - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - -

¹ #27
  #41

² https://www.igvita.com/2013/06/20/http-archive-bigquery-web-performance-answers/

  Query used:

    select count(requestid) as number_of_requests,
           mimetype as media_type
    from [httparchive:runs.2014_09_01_requests]
    group by media_type
    order by number_of_requests desc;

³ db69327
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