Forum Moderators: phranque

Message Too Old, No Replies

How Include js Files In htaccess Cache Control Rules

         

Jennnnn

1:12 am on May 9, 2019 (gmt 0)

5+ Year Member Top Contributors Of The Month



I want to add cache control to my htaccess file. I’m uncertain as to how to include my js files. I’ve seen two methods:

1. ExpiresByType text/javascript “access plus 7 days"

2. ExpiresByType application/x-javascript “access plus 7 days”

My site uses jquery, slimmenu and html5 js files.

What is the different between “text/javascript” and “application/x-javascript”? Do I need both?

Thanks for your help!

phranque

3:40 am on May 9, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I’m uncertain as to how to include my js files. I’ve seen two methods:

which mime type(s) are supplied in the Content-Type response headers with your js files?

you can do both and the server will only use the one relevant to the mime type of the response:
https://httpd.apache.org/docs/current/mod/mod_expires.html#expiresbytype

What is the different between “text/javascript” and “application/x-javascript”? Do I need both?

it's actually worse than that:
RFC 4329 Scripting Media Types April 2006 [rfc-editor.org]

Various unregistered media types have been used in an ad-hoc fashion
to label and exchange programs written in ECMAScript and JavaScript.
These include:

+-----------------------------------------------------+
| text/javascript | text/ecmascript |
| text/javascript1.0 | text/javascript1.1 |
| text/javascript1.2 | text/javascript1.3 |
| text/javascript1.4 | text/javascript1.5 |
| text/jscript | text/livescript |
| text/x-javascript | text/x-ecmascript |
| application/x-javascript | application/x-ecmascript |
| application/javascript | application/ecmascript |
+-----------------------------------------------------+


Use of the "text" top-level type for this kind of content is known to
be problematic. This document thus defines text/javascript and text/
ecmascript but marks them as "obsolete". Use of experimental and
unregistered media types, as listed in part above, is discouraged.
The media types,

* application/javascript
* application/ecmascript

which are also defined in this document, are intended for common use
and should be used instead.