laravel-http2-server-push icon indicating copy to clipboard operation
laravel-http2-server-push copied to clipboard

Add helpers for other types of content

Open kohenkatz opened this issue 9 years ago • 4 comments

I can do a PR for this, but first I wanted to gauge interest.

The preload spec that defines server push lists the valid "request destination" types for the as attribute of the Link header. Of those, only image, script, and style have helpers in this package. While those are likely the most commonly used, I think that we should make it easier for users to specify the other types.

There are two ways that I can think of to do this:

  1. Add a generic helper pushFile that has a second argument which defines the type.
  2. Add helpers for all of the types.

Here is the example list of types from the documentation (including the three types already supported):

  • media - for <audio> and <video> tags
  • script - for <script> tags and importScripts calls (inside workers)
  • style - for <link rel=stylesheet> and @import
  • font - for CSS @font-face - this should also have a type attribute which holds the mime type of the font file
  • image - for <img>, <picture>, srcset, imageset, SVG's <image> tag, CSS *-image
  • none - for XHR, fetch
  • worker - for Worker, SharedWorker
  • embed - for <embed>
  • object - for <object>
  • document - for <iframe> and <frame>

The spec also defines the following types, but they are not listed in this part of the documentation:

  • report
  • serviceworker
  • sharedworker
  • manifest
  • xslt

Thoughts?

kohenkatz avatar Aug 18 '16 02:08 kohenkatz

Yeah this has been on my todo list since I created the package but I haven't found the time yet...

I'd be all for a PR if you have the time to do so!

Maybe we go for a generic pushItem($path, $type) method but keep the ones for image, style, script.

tomschlick avatar Aug 18 '16 02:08 tomschlick

Some time in the next few days I will try to get a PR in for a pushItem helper.

In addition to $path, and $type, there will also be a $mimeType argument for things like font to use. It will default to null because it isn't needed everywhere.

kohenkatz avatar Aug 18 '16 03:08 kohenkatz

Sounds good. Thanks!

tomschlick avatar Aug 18 '16 03:08 tomschlick

Hi everyone,

I created a PR that supports Fonts, could be useful for you

PR: https://github.com/tomschlick/laravel-http2-server-push/pull/19

regiszanandrea avatar May 23 '18 02:05 regiszanandrea