为 glassfish 网络服务器缓存 css、js 和字体缓存的最佳方式

问题描述 投票:0回答:1

我有 Glassfish Web 服务器,我希望我的应用程序在客户端缓存文件,我尝试了多种方法,它对任何方法都不起作用,并且某些方法使用 apache Web 服务器,这不适合我的情况,基本上我的 html 文件中有这个(是 html 文件):


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Wait Application Load</title>
    <link type="text/css" rel="stylesheet" href="../theme/management/loader.css">
    <script type="application/javascript" src="../js/loader.js"></script>

    <link type="text/css" rel="stylesheet" href="../plugins/bootstrap/bootstrap.rtl.min.css">
    <link type="text/css" rel="stylesheet" href="../plugins/fontawesome/css/all.min.css">
    <link type="text/css" rel="stylesheet" href="../plugins/datepicker/persian-datepicker.min.css">
    <link type="text/css" rel="stylesheet" href="../plugins/datatables/datatables.css">
    <link type="text/css" rel="stylesheet" href="../theme/management/base.css">
    <script type="application/javascript" src="../plugins/jquery/jquery-3.6.3.min.js"></script>
    <script type="application/javascript" src="../plugins/bootstrap/bootstrap.bundle.min.js"></script>
    <script type="application/javascript" src="../plugins/datepicker/persian-date.min.js"></script>
    <script type="application/javascript" src="../plugins/datepicker/persian-datepicker.min.js"></script>
    <script type="application/javascript" src="../plugins/datatables/datatables.min.js"></script>
    <script type="application/javascript" src="../theme/management/control.js"></script>
    <script type="application/javascript" src="../js/management.js"></script>
    <script type="application/javascript"
            src="../plugins/tiny/tinymce.min.js"
    ></script>
</head>

重新加载页面后的所有加载和资源文件总数为 5.9mb,对于我创建请求的任何时候来说都是巨大的!所以我想在客户端缓存这个,我尝试这个:

 <meta http-equiv="Cache-Control" content="max-age=31536000, public">

不适合我,也许会产生问题为什么我使用的html文件不是jsf或servlet或jsp!那是因为我创建了自己的引擎网站,可以更快地开发和构建。 那么在

glassfish-web.xml
web.xml
中如何创建缓存角色? 我检查了多个网站,发现旧版本不起作用。

这是我的基本

glassfish-web.xml
web.xml

<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD
GlassFish Application Server 3.1 Servlet 3.0//EN"
        "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <context-root>/</context-root>
</glassfish-web-app>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
         version="6.0">
    <error-page>
        <location>/Application/Page/Error</location>
    </error-page>
    <servlet>
        <servlet-name>facesServlet</servlet-name>
        <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>facesServlet</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <display-name>Restrict direct access to XHTML files</display-name>
        <web-resource-collection>
            <web-resource-name>XHTML files</web-resource-name>
            <url-pattern>*.xhtml</url-pattern>
        </web-resource-collection>
        <auth-constraint/>
    </security-constraint>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

我使用此链接,但它不再有效:缓存示例 GlassFish 版本:7.0.14

java jsp jsf glassfish
1个回答
0
投票

如何使用 .htaccess 文件进行缓存。像这样的东西可能会起作用:

# BEGIN Expire headers  
<IfModule mod_expires.c>  
  # Turn on the module.
  ExpiresActive on
  # Set the default expiry times.
  ExpiresDefault "access plus 2 days"
  ExpiresByType image/svg+xml "access 1 month"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType text/html "access plus 600 seconds"
</IfModule>  
© www.soinside.com 2019 - 2024. All rights reserved.