Unable to serve static assets with an efficient cache policy in Laravel 9 - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Monday, April 10, 2023

Unable to serve static assets with an efficient cache policy in Laravel 9

I am trying Serve static assets with an efficient cache policy. I am using Laravel 9 on a apache2 server.

Below is the code i have used in the .htaccess file to enable leverage browser caching:

<IfModule mod_expires.c>
  ExpiresActive On

 # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # Video
  ExpiresByType video/webm "access plus 1 year"
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/mpeg "access plus 1 year"

  # Fonts
  ExpiresByType font/ttf "access plus 1 year"
  ExpiresByType font/otf "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/font-woff "access plus 1 year"

  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType text/javascript "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"

  # Others
  ExpiresByType application/pdf "access plus 1 year"
  ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
</IfModule>

Even after adding the above code in .htaccess file, I am still getting the same error/notification in lighthouse and google search insights.

HTTP response headers:

cache-control: no-cache, private
cf-cache-status: MISS
cf-ray: 7b4367722899850d-BOM
content-encoding: gzip
content-type: text/html; charset=UTF-8
date: Fri, 07 Apr 2023 15:46:35 GMT
last-modified: Fri, 07 Apr 2023 15:46:34 GMT
server: cloudflare
set-cookie: XSRF-TOKEN=eyJpdiI6IjZLWldVc1JteUdFTkhZeVJYbU5wemc9PSIsInZhbHVlIjoiVXJMR241MjYrK3pRM0tZeDFDUWpqU0ZVcnVneHZYdUg1REo2U3hqZnhkSmsyK2piRC96dEdzQ1B1WTNKeG5VL2E5Z0Z5eHYycEhRUHFlNzliRithamQvVU9GWmpmSEVOQS9hM1FrTCsyZjVZOGplbTdzQWVzMUg4YkRGNWVzWC8iLCJtYWMiOiI4MjQwY2VjZmFkNjQzOTY1OTZmNzliNjNhZDdiYTRjMTYyNGRlNTdkZDQ0MmY4OGMxOGYwODg4ZDgwNjEzODkxIiwidGFnIjoiIn0%3D; expires=Fri, 07-Apr-2023 17:46:34 GMT; Max-Age=7200; path=/
set-cookie: phprank_session=eyJpdiI6Iks2ekpzdFhsRy9FRCs4UFBSdU5OR2c9PSIsInZhbHVlIjoiS2M0WGNwVzE1VS9YTkE4SUxFUVM1SXY1bmNEbWV5d1BJcTBZRVBzU3NlVFkzdEpBOTZTMFhDeXlRcmtxa0s3OWFwZzV2amIvY1NSZ2E0cVRxNkJsNEdPQWxSUTNrWnEvTnBUSitGRGRHTUhIREVIM2wrVmJQSkRieDBlZzdORkwiLCJtYWMiOiI4YjNhODJjZTVlYTJmOGMyMDA5OTcwZDM2NDY5N2I3NmU1MjQ1NjkzMjBlZjI5ODEzZTg2MWZhNzQzOWY5YmIxIiwidGFnIjoiIn0%3D; expires=Fri, 07-Apr-2023 17:46:34 GMT; Max-Age=7200; path=/; httponly
vary: Accept-Encoding,User-Agent

Edit 1 :

I have also added the below code in the .htaccess file:

<filesMatch ".(jpg|jpeg|png|gif|ico|svg|ttf|eot|woff|woff2)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>


source https://stackoverflow.com/questions/75959505/unable-to-serve-static-assets-with-an-efficient-cache-policy-in-laravel-9

No comments:

Post a Comment