Skip to content

Commit

Permalink
Append query param to trigger image optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlee85 committed Apr 19, 2024
1 parent a229859 commit d755545
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions examples/v7-nuxt3/lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
*/
export const relativizeURL = (str) => {
if (!str) return ''
// Return only the path and query string appended to /edgio-image/
return str.replace(/^(?:\/\/|[^/]+)*\//, '/edgio-image/')
// Only the path and query string appended to /edgio-image/.
str = str.replace(/^(?:\/\/|[^/]+)*\//, '/edgio-image/')

// Append `?auto=webp` to the URL to request WebP images while preserving any existing query string.
if (str.includes('?')) {
str += '&auto=webp'
} else {
str += '?auto=webp'
}

return str
}

export const getOrigin = (req) => {
Expand Down

0 comments on commit d755545

Please sign in to comment.