修改Liferay-web.xml中HeaderFilter的max-age配置未生效,求解决建议
Let me break down actionable steps to fix your Cache-Control max-age configuration issue in Liferay:
Confirm the Filter is Properly Mapped
Defining the filter inliferay-web.xmlisn’t enough—you need a corresponding<filter-mapping>to tell Liferay which URLs should use this filter. Double-check that you have something like this in your file:<filter-mapping> <filter-name>Header Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>Also, filter order matters: if other cache-related filters (like
CacheFilter) are mapped before the Header Filter, they might override your settings. Ensure the Header Filter mapping comes before any conflicting filters.Fix the Expires Parameter Format
TheExpiresinit-param expects an absolute timestamp (not relative seconds). Your current value86400won’t work because it’s a relative number. Instead, use a millisecond-based offset from the current time, like:<init-param> <param-name>Expires</param-name> <param-value>${now + 86400000}</param-value> </init-param>This generates a valid absolute expiration time 24 hours from now, which aligns with your max-age setting.
Clean Up the URL Ignore Pattern
Yoururl-regex-ignore-patternhas a trailing space (.+/-/.+) which might cause unintended matches or misses. Remove the space to make it.+/-/.+, and verify that the pattern only excludes URLs you actually want to ignore. If you’re unsure, temporarily comment out this parameter to see if your Cache-Control headers start appearing.Clear All Caches
Old cached responses can mask new configuration changes:- Stop your Liferay server.
- Delete the
tomcat/workandtomcat/tempdirectories (or equivalent for your app server). - Clear your browser cache completely, or test in incognito/private mode.
- Restart the server and recheck response headers.
Check for Conflicting Liferay Settings
Liferay has global cache settings inportal.propertiesthat might override your filter. Look for properties likebrowser.cache.control.max.ageor resource-specific settings (e.g., for theme assets or static resources). If these are set, they could take precedence over your Header Filter configuration.Inspect Response Headers Directly
Use your browser’s DevTools (Network tab) to check the actual response headers for the resources you care about. Look for:- Is the
Cache-Control: max-age=86400, publicheader present? - Are other headers (like
Pragma) overriding it? - Do the resources fall under the URL pattern mapped to your Header Filter?
- Is the
Verify Liferay Version Specifics
Header Filter behavior can vary between Liferay versions. For example, some older versions require additional configuration to apply headers to static resources, while newer versions might have optimized resource handling that bypasses the filter. Confirm your configuration aligns with your Liferay version’s expected setup.
内容的提问来源于stack exchange,提问作者Prashant Ballal

