[wp-hackers] Using wp-content/uploads to store dynamically created js and CSS

Otto otto at ottodestruct.com
Wed Jan 8 21:33:01 UTC 2014


On Wed, Jan 8, 2014 at 2:39 PM, Nicola Peluchetti
<nicola.peluchetti at gmail.com> wrote:
> I've read this article
> http://ottopress.com/2011/tutorial-using-the-wp_filesystem/ where Otto says
> to inline, but if i inline my js / css is not cached by the browser
> right?And we are talking about 500kb so it's not trivial.


First, are you seriously dynamically generating over 500kb of CSS/JS
files? Or are you really only generating some of the pieces of those
files while the rest of them is relatively static? What is the
"static" to "dynamic" ratio?

I ask because it's perfectly possible to make the static parts static,
and the dynamic parts inline. JS variables, inline CSS, etc. Just
because you have it all clumped together currently doesn't mean that
that is the only possible way.

Secondly, if you do generate a ton of content for whatever reasons,
you should not store any CSS or JS content in the /uploads directory.
Instead, make your own directory under /wp-content and store the files
there instead. The WP_Filesystem object has a function called
wp_content_dir() that will return the content directory on the
"remote" filesystem. Using this and the mkdir() function in that same
object, you can create your own directory to store the files in, write
them, and then use those URLs instead.

Storing content that will be included into the page in the uploads
folder is generally unsafe, due to some configurations of shared
hosting. It's relatively safe for inline media images, video, etc),
but it is not safe for CSS or JS content.

-Otto


More information about the wp-hackers mailing list