Table of Contents
回复内容:
Home Backend Development PHP Tutorial css.js后面的md5码

css.js后面的md5码

Jun 06, 2016 pm 08:39 PM
php

<code><link data-turbolinks-track="true" href="/assets/application-16e8967d7c54f145e91a867f0d5294f7.css" media="all" rel="stylesheet">

<script data-turbolinks-track="true" src="/assets/application-92d730502a703801e430d67a1f3a8563.js"></script>

<script src="/assets/locales/zh-CN-bdd4c21ca1ead5dc0f4d13251b9e4eb7.js">

大家看css和js名后面有段md5的代码,起什么作用?.如何在php实现这样的功能呢.

好好的,为什么要弄一个md5加密.
</script></code>
Copy after login
Copy after login

回复内容:

<code><link data-turbolinks-track="true" href="/assets/application-16e8967d7c54f145e91a867f0d5294f7.css" media="all" rel="stylesheet">

<script data-turbolinks-track="true" src="/assets/application-92d730502a703801e430d67a1f3a8563.js"></script>

<script src="/assets/locales/zh-CN-bdd4c21ca1ead5dc0f4d13251b9e4eb7.js">

大家看css和js名后面有段md5的代码,起什么作用?.如何在php实现这样的功能呢.

好好的,为什么要弄一个md5加密.
</script></code>
Copy after login
Copy after login

这个问题需要这样解答:

试想,你部署一个应用。开启了 expires or cache-control or max-age or etag 就是开启了缓存。

你部署这个应用的时候
里面有一个css文件

<link href="/assets/style.css" media="all" rel="stylesheet">

后来界面发生了修改,你修改了一些css,又增加了一些css,你重新将代码部署到了服务器,但是打开界面还是以前的老界面。

哦,原来是缓存在作怪。浏览器缓存是根据url路径缓存资源。

以前打开你网站的用户在缓存仍然有效的情况下,看到的还是你的老界面。

那该怎么办呢?

很简单,每一次部署的时候都要把文件名称改一下不久ok了吗?
所以你就这样部署

<link href="/assets/style.1.css" media="all" rel="stylesheet">

很好?问题搞定。用户看到了新的界面。
但是问题又来了。

我们不能每一次 都靠 改文件名吧。这样想想都是噩梦。

我们是什么人?程序员啊!!!,怎么能干这么没有脑力的纯体力活呢?写代码解决!!

有了?

每次部署的时候。将静态资源(image, css, js, html, fonts ....) 发布成一个新版本。
里面 关于 html 中的 href,src 引用标签 css 中的 url 都换掉。将文件名 hash 化。 hash 使用 时间戳 岂不是 就解决了。

正解。于是 Static asset revisioning 一词诞生。 翻译过来大概是 静态资源版本迭代。

题主的问题不知道解决没有。但是不得不提的是。

前端的事交给前端就好了,不要用php来做前端的事。

grunt-rev 和 gulp-rev 这两个项目 告诉你 可以怎么做。

要是觉得我说的不对,非要用 php 去实现。也可以。去找 symfony2。

看了这篇文章 你就明白为什么给静态资源打md5了。
http://div.io/topic/745

这应该是js css 等的静态资源问题,静态资源一般放到cdn上,cdn更新速度是很慢的,缓存的原因,所以如果一个js文件更新了,上传的话,文件名没变,是不会立即更新的,解决这个问题可以添加时间戳和md5码,时间戳的缺点就是 如果这次文件未更新,也会上传新文件,md5不会有这个问题,md5是根据文件内容算出来的,这个工作一般有自动化工具完成,比如 fis

和你取一个验证码后面要加一个 &ct=1231231231 时间戳是一样的,防止缓存吧。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles