简体   繁体   中英

Export compiled CSS and JS from Wordpress site

So you have:

SiteA : Wordpress site

SiteB : Full-scale application (Rails, either way)

My goal is to embed content from SiteA into SiteB. By content I mean post content along with all compiled CSS and JS.

For post content I found a great plugin for Wordpress, WP-API, which returns all of the JSON data associated with each post. Good start. Now for the rest... I'm wondering if either:

1) There's already a plugin written that can accomplish this, or

2) I'll have to write something. I'm not an expert with Wordpress yet, but I guess there would be a way of hi-jacking the bootloader and outputting an all.css and all.js, then write a script to send over those files from SiteA to SiteB every time they're updated. Better yet create an endpoint that just returns all of the CSS and JS and check the diff between that and what's on SiteB every so often.

I want to avoid using iframes to import the content because of the SEO disadvantages, but at least there are workarounds when loading it in with AJAX.

EDIT:::::::

I think I found (part of) what I was looking for...

/wp-admin/theme-editor.php : lines 79 - 94 This is where updates to the theme's styles are written to the style.css within the theme directory. I basically duplicated this to write to a separate file, just on my server for now - although easily it can hook into a CDN and write it there - and have SiteB refer to that file. Making progress!

This is what I would recommend .

‣ Establish a global folder within shared hosting or create one in the cloud CDN.

1.) Put both web properties on the same server / hosting. You mentioned you have this option.

Go into Wordpress and change all the file path references for the .css and .js files; and any other files you want to be ' global ' - and not just specific to the WP install.

Eg. Something like this: /wp/css/styles.css --> ../../css/styles.css

(Change reference to reach public shared-global folder)

Remove these css & js folders / files from the Wordpress CMS install directory to the base directory of your hosting where both web properties can easily share.

www.coolwebsite.com/wp/

www.coolwebsite.com/

Or

2.) Put all the 'shared / global folders and files' in the cloud on a CDN like AWS . Remove from hosting. This might be easier to manage, you can have the same absolute path for any and all web properties you want to share these common files with.

EG. similar to how google CDN hosts all these jQuery versions, libraries, and plugins.

Wouldn't setting up a Content Delivery Network (CDN) be more secure? So both your site can load them. And will reduce the loading time for both your sites.
You can also use dns prefetch using:

<link rel="dns-prefetch" href="url_to_external_cdn_domain" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM