它是安全的有告诉Apache服务器来处理的.js和.css文件作为PHP? [英] Is it safe to have tell Apache server to handle .js and .css files as PHP?

查看:411
本文介绍了它是安全的有告诉Apache服务器来处理的.js和.css文件作为PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:<一href=\"http://stackoverflow.com/questions/984004/clean-links-to-php-generated-javascript-and-css#answer-984020\">Link

我不知道,这是一个安全的事是什么?

I'm wondering, is this a safe thing to do?

假设我实现这和页面被要求有一对夫妇的JS和CSS文件链接到它。是TEXTFILES只需发送或服务器是否会先解析这些?不要有一台服务器,现在来测试它。

Suppose I implement this and a page gets requested that has a couple of JS and CSS files linked to it. Are the textfiles simply sent or does the server first parse them? Don't have a server to test it right now.

此外,这是工作的常用方法?我在想,设置您的文件,让您始终获得基于用户输入正确的实现可以pretty很难当谈到CSS和JavaScript。

Also, is this a common method of working? I'm thinking that setting up your files so you always get the correct implementation based on user input can be pretty hard when it comes to CSS and JavaScript.

推荐答案

有关动态CSS和Javascript你不'一定要到他们的.js或者.css文件。你可以做的有实际链接到生成它们,这样是不是动态的所有其他的.js和.css文件不会被PHP解析PHP脚本。一般来说这是一个坏主意,运行一切,尤其是媒体文件,通过应用服务器/动态解析除非绝对必要的(同样适用于.NET,回报率,Django的等等)。

For dynamic CSS and Javascript you dont' always have to have them in .js or .css files. What you can do there is actually link to a PHP script that generates them so that all other .js and .css files that aren't dynamic aren't parsed by PHP. Generally it is a bad idea to run everything, especially media files, through an app server/dynamic parsing unless absolutely necessary (same goes for .net, RoR, Django etc).

<link rel="stylesheet" type="text/css" href="mycss.css"/>

浏览器将相同的:

browser treats the same as:

<link rel="stylesheet" type="text/css" href="mydynamiccss.php?param=somevalue" /> // this one would be dynamic on params, location or something else maybe colors etc.

您也可以采取动态的JS或CSS和推动它通过重写所以它确实有正确的扩展,但它实际上是一个PHP文件,是动态的,以及如果你不希望你的链接和脚本标签有不正确的扩展

You can also take dynamic js or css and push it through rewrite so it does have the correct extension but it is actually a php file that is dynamic as well if you don't want your links and script tags to have incorrect extensions.

这篇关于它是安全的有告诉Apache服务器来处理的.js和.css文件作为PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆