9

Is there any kind of established MIME type for OpenGL shader program source code? I know that the official IANA table doesn't seem to mention one such, so it would have to be some experimental (x-…) or some vendor-specific (vnd.…) subtype, probably of the text/… main type. According to What is the correct file extension for GLSL shaders? there doesn't even seem to be an established file name extension for these, but that's a quite separate problem to me.

Background:
I sometimes want to include shader code in a <script> tag for some WebGL application, and I want to write the type= attribute of that tag in a way which is semantically as reasonable as possible, even though at the moment I can't think of any actuall difference such a choice would make (unless I call it text/javascript or something similarly stupid). But nevertheless, it would be nice to be already conforming to any tools which might develop over time, building on currently established standards that I don't know about yet.

Community
  • 1
  • 1
MvG
  • 57,380
  • 22
  • 148
  • 276
  • 1
    The spec calls for UTF-8 encoded Unicode, `text/plain` sounds reasonable, might double-check the server is sending `charset=utf-8` in the HTTP headers. – genpfault Mar 09 '15 at 18:46

4 Answers4

10

The draft glTF standard written by Khronos states to use text/plain for GLSL files.

Jephir
  • 1,331
  • 17
  • 16
  • Seeing as Python code uses `text/x-python` and Perl `text/x-perl`, I would say that `text/x-glsl` is more appropriate. – Tobia May 28 '22 at 12:03
1

The following site explains in greater detail how to add a custom MIME type: https://www.xsofthost.com/help/add-and-delete-mime-type-within-cpanel/

At this link, Krhonos docs state:

File Extension and MIME Type

External shader files may have any extension. The preferred MIME type is text/plain.

(However, I still see errors in Chrome and Edge with shader files - specifically, "Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec." vertex.glsl:1 )

phil1008
  • 39
  • 4
0

I was having a problem serving GLSL files in IIS when I used the fetch API. To properly serve GLSL files from IIS, I had to add a .glsl file extension to the MIME types:

  1. Open IIS and navigate to your site
  2. Double click MIME Types (it's between logging and modules)
  3. Underneath "Actions" in the right-side panel, click "Add..."
  4. Enter "glsl" under "File name extension:"
  5. Enter "text/plain" under "MIME type:"

If you get an error saying "A MIME type for this file extension already exists," close out of the "Add MIME type" window and scroll through the file extensions until you find .glsl extension. Make sure the MIME type is "text/plain." If it is and IIS is still serving the 404 page when you request a glsl file, you are out of luck :\

Rojo
  • 2,749
  • 1
  • 13
  • 34
  • I'm not sure if this was the place to write this answer... this was the second site to pop up when I googled "iis glsl" to fis this problem... I did not find anything to fix IIS not serving .glsl files. I'm just hoping I can help someone else. – Rojo Jun 14 '21 at 13:27
0

Not happy with text/plain, nor am I happy with vert, frag, vsh, fsh or even glsl.

Like someone already mentioned, a mimetype of text/plain can be seen as a javascript by default in some applications.

I'm going to adopt x-shader/x-fragment and x-shader/x-vertex until something more solid comes up.

As for the filename extension, the real problem is syntax highlighting and nothing seems to work by default on xfce-mousepad. I'm just going to use the c file extension because it looks to me like c or could be c with some pre-processor directives that are out of view. If mousepad supported syntax highlighting for glsl, vert, frag, vsh or fsh, I would adopt that but there doesn't seem to be any standards for this and I suppose it's because opengl on a web browser hasn't been much of a common application until HTML5.

Stephen Duffy
  • 467
  • 2
  • 14